Skip to content

Instantly share code, notes, and snippets.

@varna
Created January 23, 2019 12:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save varna/27c8d7db68b1204bfd524f004a90adba to your computer and use it in GitHub Desktop.
Save varna/27c8d7db68b1204bfd524f004a90adba to your computer and use it in GitHub Desktop.
The old ways...
function CommandBase(value) {
this.value = value;
}
CommandBase.prototype.GetString = function() {
return this.value;
};
function SaveTextCommand(value, prefix = 'save: ') {
CommandBase.call( this, value );
this.prefix = prefix;
}
// here, we make a new `SaveTextCommand.prototype`
// linked to `CommandBase.prototype`
SaveTextCommand.prototype = Object.create( CommandBase.prototype );
// Beware! Now `SaveTextCommand.prototype.constructor` is gone,
// and might need to be manually "fixed" if you're
// in the habit of relying on such properties!
SaveTextCommand.prototype.GetString = function() {
return this.prefix + this.value;
};
var a = new SaveTextCommand( "a" );
const res = a.GetString();
console.log(res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment