繁体   English   中英

错误:JavaScript中的Object.create

[英]Error : Object.create in javascript

我使用的是旧的JS编译器,因此当我尝试使用此指令时:

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()和此对象之间存在一些细微的差异,因此这可能会或可能不会导致问题。

更多背景

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM