Skip to content

Instantly share code, notes, and snippets.

@natac13
Created March 28, 2016 23:19
Show Gist options
  • Select an option

  • Save natac13/b9d2a5bfff0ff229ec67 to your computer and use it in GitHub Desktop.

Select an option

Save natac13/b9d2a5bfff0ff229ec67 to your computer and use it in GitHub Desktop.
// a ‘dog’ object has the value of legs = 4. Create a new var named ‘fido’ as a
// ‘dog’ object. Set fido’s age as ‘3’ and output the number of legs that
// ‘fido’ has.
//
// ES5
var dog = {
legs: 4
};
var fido = Object.create(dog);
fido.age = 3;
console.log('Fido has ' + fido.legs + ' legs!');
// ES6 for fun and since I use this most.
const dog = {
legs: 4
};
const fido = Object.assign(
{},
dog,
{ age: 3 }
);
console.log(`Fido has ${fido.legs} legs!`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment