0

Unfortunately, I need to deal with IE8 compatibility nightmares and after few hours of fixing troubles one after another I'm in a dead-end, hope someone can help me.

Babel implements inheritance thru this method:

function _inherits(subClass, superClass) {
    if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
    subClass.prototype = Object.create(superClass && superClass.prototype, {
        constructor: {
            value: subClass,
            enumerable: !1,
            writable: !0,
            configurable: !0
        }
    }), superClass && (Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass);
}

When I run this code on IE8 I'm getting this error: Object doesn't support this property or method that refers to the usage of Object.create

I tried to look for a plugin and different settings of Babel but couldn't find something that actually solve it.

Do someone know how to handle it?

Shlomi
  • 3,622
  • 5
  • 23
  • 34
  • Have you tried setting babel to output ES3 code instead of ES5? Otherwise you'll need to load an ES5 shim. – Bergi Apr 04 '17 at 20:44
  • yes, of course, the only thing has left is the inheritance issue, BTW, when I'm using the TypeScript inheritance it works fine, looks like babel's one is problematic in IE – Shlomi Apr 04 '17 at 20:47
  • 1
    Apparently [Babel cannot transpile to es3, but Typescript can](http://stackoverflow.com/a/40205612/2964675). Probably following what is suggested in the link may help you. – MarcoL Apr 04 '17 at 21:05

2 Answers2

0

As simple as possible: Object.create is not available in all Browsers (IE < 10, older Opera and Chrome editions)

TypedSource
  • 708
  • 4
  • 12
0

I solve this issue by create this simple polyfill:

if (!Object.create) {
    Object.create = function(o, properties) {
        if (typeof o !== 'object' && typeof o !== 'function') throw new TypeError('Object prototype may only be an Object: ' + o);
        else if (o === null) throw new Error("This browser's implementation of Object.create is a shim and doesn't support 'null' as the first argument.");

        //if (typeof properties != 'undefined') throw new Error("This browser's implementation of Object.create is a shim and doesn't support a second argument.");

        function F() {}

        F.prototype = o;

        return new F();
    };
}

ref: Object.create not supported in ie8

I commented the if (typeof properties != 'undefined') line because if not, i'm getting the following error:

This browser's implementation of Object.create is a shim and doesn't support a second argument.

I think it's not so safe because if some consumer will use it with the second argument (properties) it may cause an unexpected behavior but for my use case it's ok.

So far so good.

Community
  • 1
  • 1
Shlomi
  • 3,622
  • 5
  • 23
  • 34