错误:javascript中的Object.create
我使用的是旧的JS编译器,因此当我尝试使用此指令时:错误:javascript中的Object.create,javascript,prototype,Javascript,Prototype,我使用的是旧的JS编译器,因此当我尝试使用此指令时: constructor.prototype = Object.create(_super.prototype) 我要走了 Object.create不是一个函数 如何使用新的或其他东西修改此说明?尝试以下方法: constructor.prototype = {__proto__: _super.prototype}; 或者使用“空”构造函数的另一种方法: function Obj(){}; Obj.prototype = _super.
constructor.prototype = Object.create(_super.prototype)
我要走了
Object.create不是一个函数
如何使用新的或其他东西修改此说明?尝试以下方法:
constructor.prototype = {__proto__: _super.prototype};
或者使用“空”构造函数的另一种方法:
function Obj(){};
Obj.prototype = _super.prototype;
constructor.prototype = new Obj();
Object.create()
是EMCAScript 5的一项功能
您可以通过以下方式进行模拟:
if (typeof Object.create === 'undefined') {
Object.create = function (o) {
function F() {}
F.prototype = o;
return new F();
};
}
但是,本机Object.create()
与此之间存在一些细微的差异,因此这可能会也可能不会导致问题
更多。但是
\uuuuu proto\uuuuu
将在FF/Chrome
中工作,我们仍然不太确定OP的浏览器是的,我知道。因此,我添加了另一个approach@RomanPerekhrest我尝试了第一个,它很有效谢谢,但我对Object也有同样的问题。DefineProperty你的编译器和浏览器类型、版本是什么?