I am working on a tool that creates GUIs by assembling it from smaller pieces of the user's choice. these smaller pieces are html elements that are created programaticly.
with efficiency in mind I wondered if these elements could share a prototype, just like plain javascript objects can.
this is my method for extending:
var extend = function(o){
var F = function(){};
F.prototype = o;
var x = new F();
x._proto_ = o;
return x;
};
which is the same as Object.create(), it just keeps a reference to the prototype as in Mozilla.
so this works fine for plain objects:
var a = { x: 0, y: 1};
var b = extend(a);
b.y; // 1
but when I try to use it for actual html element it fails:
var a = document.createElement("div");
a.whatever = //whatever..
var b = extend(a);
document.body.appendChild(b); //this throws an error.
the error reads: "An attempt was made to reference a Node in a context where it does not exist."
what's the deal? is it not possible to do this with html elements?
any thoughts are appreciated..