Created
July 22, 2011 20:17
-
-
Save anonymous/1100327 to your computer and use it in GitHub Desktop.
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
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 = 10; | |
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() | |
"I'm Rich. Turn it up to 0" | |
rich.brains = 11 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment