This is an example proposal for: http://wiki.ecmascript.org/doku.php?id=strawman:default_operator
Last active
October 6, 2015 02:48
-
-
Save balupton/2923124 to your computer and use it in GitHub Desktop.
JavaScript Default Operator Prototyping
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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