1. 程式人生 > >Object.create(null) 和 {} 區別是什麼

Object.create(null) 和 {} 區別是什麼

Object.create(null)沒有繼承任何原型方法,也就是說它的原型鏈沒有上一層。

console.log(Object.create({}).toString);   // function toString() { [native code] }
console.log(Object.create(null).toString); // undefined