Created
January 23, 2019 12:14
-
-
Save varna/27c8d7db68b1204bfd524f004a90adba to your computer and use it in GitHub Desktop.
The old ways...
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
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