首页 > 其他 > 详细

Object.create

时间:2014-04-04 12:33:12      阅读:509      评论:0      收藏:0      [点我收藏+]
var emptyObject = Object.create(null);

 

var emptyObject = Object.create(null);

var emptyObject = {};

var emptyObject = new Object();

 

区别:

bubuko.com,布布扣
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 } });
bubuko.com,布布扣

 

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


如果您觉得这文章对您有帮助,请点击【推荐一下】,想跟我一起进步么?那就【关注】我吧!

Object.create,布布扣,bubuko.com

Object.create

原文:http://www.cnblogs.com/aaronjs/p/3643828.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!