-
-
Save richcollins/1100576 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Proto = { | |
protoFn: new Function, | |
clone: function() | |
{ | |
Proto.protoFn.prototype = this; | |
var clone = new Proto.protoFn(); | |
if (clone.init) | |
{ | |
clone.init(); | |
} | |
return clone; | |
} | |
} | |
var Person = Proto.clone(); | |
Person.introduce = function(){ console.log(this.name) }; | |
Person.name = "Adam"; | |
Person.introduce(); //Adam | |
var sean = Person.clone(); | |
sean.name = "Sean"; | |
sean.introduce(); //Sean | |
var Smarty = Person.clone(); | |
Smarty.brains = function(){ throw new Error("Override Me") } | |
Smarty.introduce = function(){ console.log("I'm " + this.name + ". Turn it up to " + this.brains()) | |
var rich = Smarty.clone(); | |
rich.name = "Rich" | |
//oops, forgot to update brains | |
rich.introduce() //exception | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment