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…
ECMAScript 5 中引入了一个新方法:Object.create().可以调用这个方法来创建一个新对象.新对象的原型就是调用 create 方法时传入的第一个参数: var a = {a: 1}; // a ---> Object.prototype ---> null var b = Object.create(a); // b ---> a ---> Object.prototype ---> null console.log(b.a); // 1 (继承而来)…
if (!Object.create) { Object.create = (function(){ function F(){} return function(o){ if (arguments.length != 1) { throw new Error('Object.create implementation only accepts one parameter.'); } F.prototype = o; return new F() } })() }…