Skip to content

Instantly share code, notes, and snippets.

@balupton
Last active October 6, 2015 02:48
Show Gist options
  • Save balupton/2923124 to your computer and use it in GitHub Desktop.
Save balupton/2923124 to your computer and use it in GitHub Desktop.
JavaScript Default Operator Prototyping
var prepareDrink = function(what,times){
// Prepare arguments
what ||= "martini";
times ?= 3;
// Prepare the drink
if ( opts.times === 0 ) {
console.log("You like your "+what+" stirred, not shaken");
}
else {
console.log("You like your "+what+" shaken "+times+" times, not stirred");
}
}
prepareDrink();
// ^ You like your martini shaken 3 times, not stirred
prepareDrink(0, 0);
// ^ You like your martini stirred, not shaken
prepareDrink("smoothie", 500);
// ^ You like your smoothie shaken 500 times, not stirred
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment