Skip to content

Instantly share code, notes, and snippets.

View tcare's full-sized avatar

Tom Care tcare

View GitHub Profile
@tcare
tcare / es5-no-classes-impl.js
Last active August 29, 2015 14:11
ES5 code, without classes
/* 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;
};
@tcare
tcare / es6-classes-impl.js
Last active August 29, 2015 14:11
ES6 code, with classes
/* ES6 code, with classes */
class Civilian {
constructor(name) {
this.name = name;
}
danger() {
console.log("Run away!");
}
};
@tcare
tcare / classes-syntax.js
Last active August 29, 2015 14:11
ES6 Classes Syntax Example
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; }
@tcare
tcare / super-eval.js
Last active February 22, 2016 10:29
The use of super() in an eval() introduces complexity in the compiler implementation.
/* 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