Object.create

var emptyObject = Object.create(null);

var emptyObject = Object.create(null);

var emptyObject = {};

var emptyObject = new Object();

区别:

var o;  

// create an object with null as prototype
o = Object.create(null); o = {};
// is equivalent to:
o = Object.create(Object.prototype); function Constructor(){}
o = new Constructor();
// is equivalent to:
o = Object.create(Constructor.prototype);
// Of course, if there is actual initialization code in the Constructor function, the Object.create cannot reflect it // create a new object whose prototype is a new, empty object
// and a adding single property 'p', with value 42
o = Object.create({}, { p: { value: 42 } }) // by default properties ARE NOT writable, enumerable or configurable:
o.p = 24
o.p
//42 o.q = 12
for (var prop in o) {
console.log(prop)
}
//"q" delete o.p
//false //to specify an ES3 property
o2 = Object.create({}, { p: { value: 42, writable: true, enumerable: true, configurable: true } });

https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/create

上一篇:用 WEKA 进行数据挖掘,第 1 部分: 简介和回归(转)


下一篇:解决小米、红米及其他 Android 手机无法在 Mac 下进行真机调试的问题(转)