Javascript Object.create 在 Firefox 中不起作用
我总是在 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 中工作?
I always get the following exception in Firefox (3.6.14):
TypeError: Object.create is not a function
It is quite confusing because I am pretty sure it is a function and the code works as intended on Chrome.
The lines of code responsible for this behavior are the following:
Object.create( Hand ).init( cardArr );
Object.create( Card ).init( value, suit );
It is from a poker library gaga.js if someone wants to see all the code: https://github.com/SlexAxton/gaga.js
Maybe someone knows how to get it working in Firefox?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Object.create()
是 EMCAScript5 的一项新功能。遗憾的是,它没有得到本机代码的广泛支持。尽管您应该能够使用此代码片段添加非本机支持。
我相信这是来自 Crockford 的 Javascript:好的部分。
Object.create()
is a new feature of EMCAScript5. Sadly it is not widely supported with native code.Though you should be able to add non-native support with this snippet.
Which I believe is from Crockford's Javascript: The Good Parts.
Object.create
是一部分ES5 的版本,仅在 Firefox 4 中可用。只要您没有为浏览器进行任何附加开发,您就不应该期望浏览器实现 ES5 功能(尤其是较旧的浏览器)。然后,您必须提供自己的实现(就像自己的实现一样由@Squeegy提供)。
Object.create
is part of ES5 and only available in Firefox 4.As long as you are not doing any add-on development for browsers, you should not expect browsers to implement ES5 features (especially older browsers). You'd have to provide your own implementation then (like the own provided by @Squeegy).
我使用这种方式(也在 ECMAScript 3 中工作):-
I use this way(also working in ECMAScript 3):-