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 } });
复制代码

 

本文转自艾伦 Aaron博客园博客,原文链接:http://www.cnblogs.com/aaronjs/p/3643828.html,如需转载请自行联系原作者

相关文章
|
5月前
|
SQL IDE Java
hibernate5 Cannot create TypedQuery for query with more than one return using requested result type
hibernate5 Cannot create TypedQuery for query with more than one return using requested result type
65 0
|
存储 网络协议 网络安全
MQTTClient_create函数
MQTTClient_create函数
260 0
|
5月前
|
索引
(详解)Object.keys() Object.values() Object.entries()
(详解)Object.keys() Object.values() Object.entries()
40 1
Object.create()方法与new操作的区别
Object.create()方法与new操作的区别
142 0
Object.create()方法与new操作的区别
test of duplicate control id
Created by Jerry Wang, last modified on Aug 21, 2015
test of duplicate control id
Object.keys与for in,Object.getOwnPropertyNames的区别
for/in: 是ES3中的方法,用来遍历对象(集合)的方法; 不过,for/in 会输出自身以及原型链上可枚举的属性,可以使用 hasOwnProperty 来过滤原型链上的属性 Object.
1657 0
|
索引 关系型数据库 Oracle
20171229V$DB_OBJECT_CACHE type='INDEX'
[20171229]V$DB_OBJECT_CACHE type='INDEX'.txt --//前几天一直在使用V$DB_OBJECT_CACHE视图查询FULL_HASH_VALUE,验证自己推断FULL_HASH_VALUE如何计算.
1081 0
|
开发工具