Your solution is working correctly using babel. Your code will compile into the following ES5 code.
// Library written in ES5 "use strict"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { 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: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; } function Creature(type) { this.type = type; } // my code in ES6 var Fish = (function (_Creature) { function Fish(name) { _classCallCheck(this, Fish); _Creature.call(this, "fish"); this.name = name; } _inherits(Fish, _Creature); return Fish; })(Creature);
As you can see from the above code, the constructor of the Creature class is called correctly. String _Creature.call(this, "fish"); .
Important link
I added the following code to demonstrate that the fish is an instance of Creature as well as an instance of Fish .
var fish = new Fish("test"); console.log(fish.type); console.log(fish.name); console.log( fish instanceof Creature ); console.log( fish instanceof Fish);
Output:
fish test true true
source share