Skip to content

Instantly share code, notes, and snippets.

@juliocesar
Created May 3, 2013 04:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juliocesar/5507189 to your computer and use it in GitHub Desktop.
Save juliocesar/5507189 to your computer and use it in GitHub Desktop.
ES6 - method parameter changes
// 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