我在 Firefox (3.6.14) 中总是遇到以下异常:
TypeError: Object.create is not a function
这很令人困惑,因为我很确定它是一个函数,并且代码在 Chrome 上按预期工作。
负责此行为的代码行如下:
Object.create( Hand ).init( cardArr );
Object.create( Card ).init( value, suit );
如果有人想查看所有代码,它来自扑克库 gaga.js:https://github.com/SlexAxton/gaga.js
也许有人知道如何让它在 Firefox 中工作?
最佳答案
Object.create()
是 EMCAScript5 的新功能。遗憾的是, native 代码并未广泛支持它。
虽然您应该能够使用此代码段添加非本地支持。
if (typeof Object.create === 'undefined') {
Object.create = function (o) {
function F() {}
F.prototype = o;
return new F();
};
}
我相信这是来自 Crockford 的 Javascript: The Good Parts。
关于Javascript Object.create 在 Firefox 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5199126/