This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ES5 code, without classes */ | |
var Civilian = function Civilian(name) { | |
this.name = name; | |
}; | |
Civilian.prototype.danger = function () { console.log("Run away!"); }; | |
var SuperHero = function(name, ability) { | |
Civilian.call(this, name); // Call the super class constructor. | |
this.ability = ability; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ES6 code, with classes */ | |
class Civilian { | |
constructor(name) { | |
this.name = name; | |
} | |
danger() { | |
console.log("Run away!"); | |
} | |
}; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Parent { | |
constructor() { } // Custom constructor (optional.) If one is not provided, the example here is used a default constructor. | |
// Methods | |
method() { } // Simple instance methods | |
static staticMethod() { } // Static methods that can be called on the constructor, e.g. A.staticMethod. | |
// Getter/setter methods - similar to ES5 equivalents. | |
get prop() { return this.x; } | |
set prop(x) { this.x = x; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* The use of super() in an eval() introduces complexity in the compiler implementation. */ | |
class Child extends Parent { | |
method() { | |
// This method needs a reference to Parent available when super() is called. | |
// Chakra can determine this during the Parser stage. | |
super(); | |
} | |
methodEval() { | |
// This method also needs a reference to Parent available when super() is | |
// called, however Chakra doesn’t know for sure until we execute the code |