Skip to content

Instantly share code, notes, and snippets.

@tcrosen
Last active January 18, 2016 03:06
Show Gist options
  • Save tcrosen/4d08a00dd734c2c8d2f4 to your computer and use it in GitHub Desktop.
Save tcrosen/4d08a00dd734c2c8d2f4 to your computer and use it in GitHub Desktop.
// 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