Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/457.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
错误:javascript中的Object.create_Javascript_Prototype - Fatal编程技术网

错误:javascript中的Object.create

错误: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.

我使用的是旧的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()
与此之间存在一些细微的差异,因此这可能会也可能不会导致问题


更多。

但是
\uuuuu proto\uuuuu
将在
FF/Chrome
中工作,我们仍然不太确定OP的浏览器是的,我知道。因此,我添加了另一个approach@RomanPerekhrest我尝试了第一个,它很有效谢谢,但我对Object也有同样的问题。DefineProperty你的编译器和浏览器类型、版本是什么?