question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

super() not calling parent's constructor on IE9

See original GitHub issue

Hello,

After upgrading to babel@6.0.14, babelify@7.1.0 and babel-preset-es2015@ 6.0.14 it seems that on IE9, calling super() on a child class’ constructor doesn’t call the parent’s constructor anymore.

The two classes live on different files and I import/export the whole using the ES2015 module syntax.

Like so:

// in myClassA.js
export class A {
    constructor() {
        console.log('I am your father');
    }

    init() {
        console.log('And I know who your sister is');
    }
}

// in myClassB.js
import {A} from './myClassA.js';

export class B extends A {
    constructor() {
        // Won't do anything
        super();
    }

    init() {
        // Will fire A.init() properly: 'And I know who your sister is' is logged
        super.init();
    }
}

// Wherever else
import {B} from './myClassB';

window.onload = () => {
    var B = new B();
}

And in my gulp task:

(...).transform(babel.configure({
    presets: ["es2015"],
    ignore: ["client/vendor"]
}));

It’s working well on IE >= 10 but unfortunately not on IE9. I’m opening the issue on the babelify repo since I’m using it but maybe it belongs to the babel one.

Reverting back to babel@5 and babelify@6 fixes the issue.

Thanks for the support and continue the good work guys !

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:16 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
rxavierscommented, Jun 7, 2016

Please, what’s the final word on this? It seems like super doesn’t work on <=IE10 except if using es2015-loose preset. Is that correct? Is that the suggested approach/workaround or is there a better solution that doesn’t make use of the loose mode (e.g., inclusion of a polyfill?)? Should http://babeljs.io/docs/plugins/transform-es2015-object-super/ include a list of supported browsers? Thank you

4reactions
peternoordijkcommented, Apr 20, 2016

Is this still an issue? I tried to run a few tests and I didn’t encounter any problems anymore on IE9. I used the es2015-loose preset without transform-proto-to-assign. My code is in here: https://jsfiddle.net/peternoordijk/ymtyud9y/

Read more comments on GitHub >

github_iconTop Results From Across the Web

In JavaScript, why super keyword is not calling always parent ...
super does always call the "parent" class methods. But your log "Message 2 from Child class" is caused by this.msg2() in the parent...
Read more >
simpledeclare - npm
Easy calling of asyncronous super methods with this.inheritedAsync(); Automatic execution of all constructors in the right order; Automatic inheritance of ...
Read more >
CoffeeScript
Identical to calling coffee with no arguments. ... Or if you know that the parent function doesn't require arguments, just call super() :....
Read more >
Inheritance in JavaScript
Note that we've only specified this inside call() — no other ... To call the parent constructor we have to use the super()...
Read more >
Finally Understanding the Advanced uses of "This" in Javascript
The above will call Whatever (or its constructor function if it's a ... if the function is called without its parent object, or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found