Skip to content

Instantly share code, notes, and snippets.

@mrgenixus
Created March 7, 2018 23:09
Show Gist options
  • Save mrgenixus/673e919911e4a3b8b78b2001d8c5abb7 to your computer and use it in GitHub Desktop.
Save mrgenixus/673e919911e4a3b8b78b2001d8c5abb7 to your computer and use it in GitHub Desktop.
es6 classes
function ParentWidget(properties) {
Object.assign(this, properties);
}
function farewell() {
console.log('Goodbye Cruel ' + this.name);
}
ParentWidget.prototype.farewell = farewell;
function Widget(properties) {
ParentWidget.call(this, properties);
}
Widget.prototype.prototype = ParentWidget.prototype
Object.assign(Widget.prototype, {
farewell: function farewell() {
ParentWidget.prototype.farewell();
},
greet: function greet() {
console.log("Hello " + this.name);
}
});
// usage:
var widget = new Widget({ name: 'Ben' });
widget.greet(); // Hello Ben
widget.farewell(); // Goodbye Cruel Ben
//es6
class ParentWidget {
constructor(properties) {
Object.assign(this, properties);
}
farewell() {
console.log('Goodbye Cruel ' + this.name);
}
}
class Widget extends ParentWidget {
farewell() {
super();
}
greet() {
console.log("Hello " + this.name);
}
}
widget.greet(); // Hello Ben
widget.farewell(); // Goodbye Cruel Ben
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment