Skip to content

Instantly share code, notes, and snippets.

@getify
Forked from spikesagal/run.js
Last active October 1, 2015 17:49
Show Gist options
  • Save getify/afbede4e336978616d19 to your computer and use it in GitHub Desktop.
Save getify/afbede4e336978616d19 to your computer and use it in GitHub Desktop.
ES6 destructure named args into properties of constructed object (this).
'use strict';
class Person {
constructor({
firstName: this.firstName = '<FIRSTNAME_UNKNOWN>',
lastName: this.lastName = '<LASTNAME_UNKNOWN>'
} = {}) {}
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