Object.create(null)与{}
Object.create实现
Object.create = funtion(o){
var f = function(){};
f.prototype = o;
return new f();
}Object.create(null)输出
let a = Object.create(null)
console.log(a)
------------------
{}
no properties{}输出
let o = {}
console.log(o)
--------------------
{}
__proto__:
constructor
hasOwnProperty
isPrototypreOf
...使用create创建的对象,没有任何属性,显示No properties,我们可以把它当作一个非常纯净的map来使用,我们可以自己定义hasOwnProperty、toString方法,不管是有意还是不小心,我们完全不必担心会将原型链上的同名方法覆盖掉。
最后更新于
这有帮助吗?