1
<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?

user2294256
  • 1,029
  • 1
  • 13
  • 22

3 Answers3

1

try:

var zack = Object.create(person, {age: {value:  13, enumerable:true} });
console.log(zack); 
Sudhir Bastakoti
  • 99,167
  • 15
  • 158
  • 162
1

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.

Community
  • 1
  • 1
Niccolò Campolungo
  • 11,824
  • 4
  • 32
  • 39
0

use enumerable: true inside. It should work.

Also check this thread about enumerable property. What is the enumerable argument for in Object.create?

Community
  • 1
  • 1