-
-
Save getify/afbede4e336978616d19 to your computer and use it in GitHub Desktop.
ES6 destructure named args into properties of constructed object (this).
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
'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