
Untitled
By: a guest on
May 5th, 2012 | syntax:
None | size: 0.69 KB | hits: 8 | expires: Never
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