2016-02-17 28 views
0

我有一個老JS編譯工作,所以當我與該指令嘗試:錯誤:在的Object.create的JavaScript

constructor.prototype = Object.create(_super.prototype) 

我越來越

的Object.create不是一個函數

我該如何修改這個指令,使用新的或其他的東西?

+0

什麼是您的編譯器和瀏覽器類型,版本? –

回答

0

試試這個辦法:

constructor.prototype = {__proto__: _super.prototype}; 

或 '空' 構造另一種方法:

function Obj(){}; 
Obj.prototype = _super.prototype; 

constructor.prototype = new Obj(); 
+0

但'__proto__'將在FF/Chrome中運行,我們仍然不太確定OP的瀏覽器 –

+0

是的,我知道。因此,我已經添加了另一種方法 – RomanPerekhrest

+0

@RomanPerekhrest我試了第一個,它的工作原理謝謝,但我有同樣的問題與Object.defineProperty – ameni

0

Object.create()是EMCAScript 5功能。

您可以通過效仿:

if (typeof Object.create === 'undefined') { 
    Object.create = function (o) { 
     function F() {} 
     F.prototype = o; 
     return new F(); 
    }; 
} 

不過,也有本土Object.create(),這之間有一些細微的差別,所以這可能會或可能不會導致在路上的問題。

更多background