Object.create()和new Object()
Object.create(null) 創(chuàng)建的對(duì)象是一個(gè)空對(duì)象,在該對(duì)象上沒有繼承 Object.prototype 原型鏈上的屬性或者方法,例如:toString(), hasOwnProperty()等方法
Object.create()方法接受兩個(gè)參數(shù):Object.create(obj,propertiesObject);
obj:一個(gè)對(duì)象,應(yīng)該是新創(chuàng)建的對(duì)象的原型。
propertiesObject:可選.
使用Object.create()是將對(duì)象繼承到__proto__屬性上
var test = Object.create({x: 123, y: 345});
console.log(test);
console.log(test.x)
console.log(test.__proto__.x)
console.log(test.__proto__.x === test.x);
var test1 = new Object({x: 123, y: 345});
console.log(test1);
console.log(test1.x);
console.log(test1.__proto__.x)
console.log(test1.__proto__.x === test1.x);
var test2 = {x: 123, y: 345};
console.log(test2);
console.log(test2.x);
console.log(test2.__proto__.x);
console.log(test2.__proto__.x === test2.x)
轉(zhuǎn)載于:https://www.cnblogs.com/insignificant-malt/p/8558579.html
《新程序員》:云原生和全面數(shù)字化實(shí)踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀總結(jié)
以上是生活随笔為你收集整理的Object.create()和new Object()的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 服务器资源数据结果汇总
- 下一篇: sqoop/1.4.6/下载