3 回答
TA贡献1852条经验 获得超7个赞
在Object.create中使用的对象实际上构成了新对象的原型,其中与新函数()形式一样,声明的属性/函数并不构成原型。
Object.create
var o = new SomeConstructor();
oSomeConstructor.prototype.
Object.createObject.create(null);SomeConstructor.prototype = null;Object.prototype.
不能像使用函数语法那样使用Object.create语法创建闭包。考虑到JavaScript的词法(VS块)类型范围,这是合乎逻辑的。
var o = Object.create({inherited: 1}, {
foo: {
get: (function () { // a closure
var closured = 'foo';
return function () {
return closured+'bar';
};
})()
}});o.foo; // "foobar"Object.create
TA贡献1789条经验 获得超10个赞
new XObject.create(X.prototype)constructorconstructorreturnthis.)
new
添加回答
举报
