fish man
fish man

Reputation: 101

new to javascript: Internet Explorer 8 does not support object.create()

new to javascript: Internet Explorer 8 does not support object.create(), here is an example:

var tilo = Object.create(Person); 

ok, so IE does not support it. What should I do next? Should I create 2 different javascript files.. one for Firefox, one for IE ?

Upvotes: 0

Views: 208

Answers (1)

Ian
Ian

Reputation: 50905

From MDN's docs, use this:

if (!Object.create) {
    Object.create = (function () {
        var F = function(){};

        return function (o) {
            if (arguments.length !== 1) {
                throw new Error('Object.create implementation only accepts one parameter.');
            }
            F.prototype = o;
            return new F();
        };
    }());
}

Include this on your page before you attempt to use Object.create. It detects if it's natively available; if it's not, it makes it available by using this custom code. This should technically make it available in any browser.

You should never make script files for specific browsers; browser versions differ in their feature support...that's why you should always use feature detection (like this code). Internet Explorer 9 supports this, so you shouldn't generalize that IE needs it.

Reference:

Upvotes: 6

Related Questions