Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript Object.create not working in 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?

like image 217
dominos Avatar asked Dec 13 '22 15:12

dominos


1 Answers

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.

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

Which I believe is from Crockford's Javascript: The Good Parts.

like image 125
Alex Wayne Avatar answered Dec 29 '22 18:12

Alex Wayne