2 ms·
This is faster (don't keep calling new Function) and more OO (send message to prototype to clone it): Proto = { cloneConstructor: new Function,
by richcollins 15y ago
This is faster (don't keep calling new Function) and more OO (send message to prototype to clone it):
Proto = {
cloneConstructor: new Function,
clone: function()
{
Proto.cloneConstructor.prototype = this;
return new Proto.cloneConstructor;
}
}
var Point = Proto.clone();
Point.x = 0;
Point.y = 0;
Point.print = function()
{
console.log(this.x, this.y);
}
var p = Point.clone();
p.x = 10;
p.y = 20;
p.print(); //10 20