Javascript Object.create 在 Firefox 中不起作用

标签 javascript object-create

我在 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/

相关文章:

JavaScript Object.create——继承嵌套属性

javascript - 当用户单击链接或页面中的其他任何位置时,JS 隐藏菜单

javascript - 并在 Parse Cloud 代码上查询

javascript - 原型(prototype)继承: Can you chain Object.创建?

node.js - 如何在 Node.js 的模块内使用 Object.create 进行继承

javascript - Object.create 和原型(prototype)

javascript - 带有 Object.create 和命名构造函数的原型(prototype) OO

javascript - 如何从 app.js 处理 Express 4/nodejs 中的获取/发布,将数据从表单传递到显示结果的新页面

javascript - Jquery:在.append中传递ID

php - ui slider 上的值