Last active
January 18, 2016 03:06
-
-
Save tcrosen/4d08a00dd734c2c8d2f4 to your computer and use it in GitHub Desktop.
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
// Destructuring alternative | |
constructor(props = {}) { | |
const { firstName = 'John', lastName = 'Doe' } = props; | |
this.firstName = firstName; | |
this.lastName = lastName; | |
} | |
// Destructuring alternative | |
constructor(props) { | |
const { firstName = 'John', lastName = 'Doe' } = props || {}; | |
this.firstName = firstName; | |
this.lastName = lastName; | |
} | |
// Using Object.assign() (or _.assign) | |
constructor(props) { | |
const defaults = { | |
firstName: 'John', | |
lastName: 'Doe' | |
}; | |
Object.assign(this, defaults, props); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment