Skip to content

Instantly share code, notes, and snippets.

@spikesagal
Created October 1, 2015 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save spikesagal/4aa02c82dae6da8fe632 to your computer and use it in GitHub Desktop.
Save spikesagal/4aa02c82dae6da8fe632 to your computer and use it in GitHub Desktop.
ES6 destructure named args into properties of constructed object (this).
'use strict';
class Person {
constructor(arg = {
firstName: 'John',
lastName: 'Doe'
}) {
({
firstName: this.firstName = '<FIRSTNAME_UNKNOWN>',
lastName: this.lastName = '<LASTNAME_UNKNOWN>'
} = arg);
}
printName() {
console.log(this.lastName, ',', this.firstName);
}
}
var person;
person = new Person({
firstName: 'Alex'
})
person.printName();
person = new Person;
person.printName();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment