[英]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.