Skip to content

Instantly share code, notes, and snippets.

@binnng
Last active December 16, 2015 03:49
Show Gist options
  • Save binnng/5372523 to your computer and use it in GitHub Desktop.
Save binnng/5372523 to your computer and use it in GitHub Desktop.
Object.create创建对象, 疑惑的地方。具体看代码
var O = {a: 1};
var n = Object.create(O, {
a: {
value: 2
}
});
console.log(n); //{a: 1}
console.log(n.a); //2
@fakefish
Copy link

for(var i in n){
console.log(n[i]);
}
// return 2

我发现似乎只有这样才能选出,提供的这些配置好像没用(≧m≦)

var O = {a: 1};

var n = Object.create(O, {
  a: {
    value: 2,
    enumerable:true
  }
});
console.log(n); 

console.log(n.a); 
//Object {a: 2, a: 1}
//2

这算个鸟啊 都不覆盖

@LiuJi-Jim
Copy link

enumerable: true

@binnng
Copy link
Author

binnng commented Apr 13, 2013

@fakefish 我也奇怪,为毛不能覆盖。设置时需要定义enumerable(可枚举),才能被看见。回去查查文档。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment