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
Object.create的更多相关文章
- 使用Object.create 克隆对象以及实现单继承
var Plane = function () { this.blood = 100; this.attack = 1; this.defense = 1; }; var plane = new Pl ...
- 【前端】js中new和Object.create()的区别
js中new和Object.create()的区别 var Parent = function (id) { this.id = id this.classname = 'Parent' } Pare ...
- 基本类型和引用类型调用是的区别(Object.create)
var person = { name : 'jim', address:{ province:'浙', city:'A' } } var newPerson = Object.create(pers ...
- Object.create() 和 __proto__ 的关系
经测试得出 Ojbect.create() 也就是通过修改 __proto__ 实现的. 例: var Super = { say: function() {console.log('say')} } ...
- 使用 Object.create 创建对象,super 关键字,class 关键字
ECMAScript 5 中引入了一个新方法:Object.create().可以调用这个方法来创建一个新对象.新对象的原型就是调用 create 方法时传入的第一个参数: var a = {a: 1 ...
- Object.create 函数 (JavaScript)
创建一个具有指定原型且可选择性地包含指定属性的对象. 语法 Object.create(prototype, descriptors) 参数 prototype 必需. 要用作原型的对象. 可以为 ...
- 构造函数创建对象和Object.create()实现继承
第一个方法用构造函数创建对象,实现方法的继承 /*创建一个对象把所有公用的属性和方法,放进去*/ function Person() { this.name = "W3cplus" ...
- Object.create()兼容实现方法
if (!Object.create) { Object.create = (function(){ function F(){} return function(o){ if (arguments. ...
- javascript一种新的对象创建方式-Object.create()
1.Object.create() 是什么? Object.create(proto [, propertiesObject ]) 是E5中提出的一种新的对象创建方式,第一个参数是要继承的原型,如果不 ...
随机推荐
- Windows Phone 8.1新特性 - 应用商店启动协议
Windows Phone 8.1 Preview SDK 发布也有几个月了,之前断断续续也写过几篇 Windows Phone 8.1 新特性的文章,今天给大家介绍一下应用商店启动协议相关的知识. ...
- C++的一个奇技淫巧
C++如何写一个函数,得到一个数组的长度呢? size_t GetArrayLength(int Array []) { return sizeof(Array)/sizeof(Array[0]); ...
- 如何参与Linux内核开发(转)
本文来源于linux内核代码的Document文件夹下的Hoto文件.Chinese translated version of Documentation/HOWTO If you have any ...
- 如何运用boolean跳出循环
用布尔类型跳出循环:1.首先申明一个布尔变量:boolean y =false:申明位置在:方法内,循环外:public void s(){//在此申明布尔变量:for(){}}if(!y){}2,进 ...
- (转)将win7电脑无线网变身WiFi热点,让手机、笔记本共享上网
将win7电脑变身WiFi热点,让手机.笔记本共享上网 功能:开启windows 7的隐藏功能:虚拟WiFi和SoftAP(即虚拟无线AP),就可以让电脑变成无线路由器,实现共享上网,节省网费和路由器 ...
- 错误 "sgen.exe" exited with code 1.解决方法(转)
原文出自 http://blog.sina.com.cn/s/blog_8411d3f401015u1w.html VS中有时候编译项目会出现这样的错误: 错误 "sgen.exe&qu ...
- 如何安全地关闭MySQL实例
如何安全地关闭MySQL实例 转载自:http://imysql.com/2014/08/13/mysql-faq-howto-shutdown-mysqld-fulgraceful.shtml 本文 ...
- Linux下Crontab命令用法
第1列分钟1-59第2列小时1-23(0表示子夜)第3列日1-31第4列月1-12第5列星期0-6(0表示星期天)第6列要运行的命令 下面是crontab的格式:分 时 日 月 星期 要运行的命令 这 ...
- 异步CTP(Async CTP)为什么那样工作?
对异步CTP感兴趣有很多原因.异步CTP使异步编程比以前更加容易了.它虽然没有Rx强大,但是更容易学.异步CTP介绍了两个新的关键字,async和await.异步方法(或Lambda表达式)必须返回v ...
- Java多线程3:Thread中的静态方法
Thread类中的静态方法 Thread类中的静态方法表示操作的线程是"正在执行静态方法所在的代码块的线程".为什么Thread类中要有静态方法,这样就能对CPU当前正在运行的线程 ...