<script>
var person = {
kind: 'person'
}
var zack = Object.create(person, {age: {value: 13} });
console.log(zack);
</script>
Question:
in firebug->console, it shows: Object { kind="person"}, why I can not see the added property: age?
<script>
var person = {
kind: 'person'
}
var zack = Object.create(person, {age: {value: 13} });
console.log(zack);
</script>
Question:
in firebug->console, it shows: Object { kind="person"}, why I can not see the added property: age?
try:
var zack = Object.create(person, {age: {value: 13, enumerable:true} });
console.log(zack);
in firebug->console, it shows: Object { kind="person"}, why I can not see the added property: age?
Object.create()
by default doesn't set the enumerable property to true! Since it is false, the property will not be shown up. See property descriptors at MDN(in this case is an accessor descriptor), this is a good reference to start!
enumerable
true if and only if this property shows up during enumeration of the properties on the corresponding object. Defaults to false.
use enumerable: true inside. It should work.
Also check this thread about enumerable property. What is the enumerable argument for in Object.create?