I\'ve come across a peculiarity with Douglas Crockfords Object.create method which I\'m hoping someone might be able to explain:
If I create an object - say \'person
That happens because anotherPerson.name
is an object and it is stored upper in the prototype chain, on the original person
object:
//...
var anotherPerson = Object.create(person);
anotherPerson.hasOwnProperty('name'); // false, the name is inherited
person.name === anotherPerson.name; // true, the same object reference
You can avoid this by assigning a new object to the name
property of the newly created object:
// create anotherPerson from person
var anotherPerson = Object.create(person);
anotherPerson.name = {
first: 'Stephen',
last: 'Merchant'
};