Today I learned

Babel class inheritance in Internet Explorer

Update (2019): This post was written for Babel version 5. Also, this post is made for supporting IE8, a version which has very negligible use in 2019.

class Circle extends Shape {
  getArea() {
    return this.radius * Math.PI * 2
  }
}

Class inheritance caveats

When using class inheritance with Babel.js, keep in mind that IE10 and below are not supported by default. Babel's class inheritance relies on ___proto___ which is not available on legacy IE versions.

Using super is also not supported on IE8 and below, as it compiles down to using Object.getPrototypeOf.

To get around these caveats, use the protoToAssign transformer to make inheritance work, along with loose mode on classes to enable support for super.

babel --optional spec.protoToAssign --loose es6.classes script.js

You have just read Babel class inheritance in Internet Explorer, written on May 26, 2015. This is Today I Learned, a collection of random tidbits I've learned through my day-to-day web development work. I'm Rico Sta. Cruz, @rstacruz on GitHub (and Twitter!).

← More articles