Created
May 3, 2013 04:20
-
-
Save juliocesar/5507189 to your computer and use it in GitHub Desktop.
ES6 - method parameter changes
This file contains 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
// ES6 method parameter changes | |
// ============================ | |
// Default argument values are possible in ES6. | |
var Person = function(name = 'John Doe') { | |
this.name = name; | |
}; | |
// var p = new Person(); | |
// p.name | |
// => "John Doe" | |
// Rest parameters, similar to CoffeeScript except the ellipsis is | |
// on the wrong side. | |
Person.prototype.put = function(recipient = [], ...stuff) { | |
for (var i = 0, l = stuff.length; i < l; i++) | |
recipient << stuff[i]; | |
return recipient; | |
} | |
// "Put in 'Basket', the rest of the parameters" | |
// p.put('Basket', 'apple', 'banana', 'orange'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment