Skip to content

Instantly share code, notes, and snippets.

Created July 22, 2011 20:17
Show Gist options
  • Save anonymous/1100327 to your computer and use it in GitHub Desktop.
Save anonymous/1100327 to your computer and use it in GitHub Desktop.
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