I am reading about JavaScript prototypes here. Under the Object.create header, some code is written out to illustrate creating objects with prototypes and certain properties:
var person = {
kind: 'person'
}
// creates a new object which prototype is person
var zack = Object.create(person);
console.log(zack.kind); // => ‘person’
I then encountered this:
var zack = Object.create(person, {age: {value: 13} });
console.log(zack.age); // => ‘13’
Instead of passing {age: {value: 13} }
, I passed {age: 13}
because it seemed simpler. Unfortunately, a TypeError
was thrown. In order to create properties of this object like this, why do we have to pass {age: {value: 13} }
rather than just {age: 13}
?