P
petermichaux
Hi,
Hopefully the group doesn't mind an(other) inheritance question. Maybe
the prototype inheritance style is starting to become a low dim light
in my brain...probably not yet.
----
If I do the following...
var a = document.getElementById("my_div");
var b = new Object();
b.prototype = a;
b.new_property = function(){alert("the new property!");
Now b has the new property. Also, b has all the properties of a.
----
Is it possible to do this more efficiently with a constructor?
Something like...
function B(element){
// what goes here?
}
B.prototype.new_property = function(){alert("the new property!")};
var a = document.getElementById("my_div");
var b = new B(a);
This way I could efficiently make many b-type objects based on
different a-type objects without having to attach new_property
explicitly to each new b-type object.
Hopefully the group doesn't mind an(other) inheritance question. Maybe
the prototype inheritance style is starting to become a low dim light
in my brain...probably not yet.
----
If I do the following...
var a = document.getElementById("my_div");
var b = new Object();
b.prototype = a;
b.new_property = function(){alert("the new property!");
Now b has the new property. Also, b has all the properties of a.
----
Is it possible to do this more efficiently with a constructor?
Something like...
function B(element){
// what goes here?
}
B.prototype.new_property = function(){alert("the new property!")};
var a = document.getElementById("my_div");
var b = new B(a);
This way I could efficiently make many b-type objects based on
different a-type objects without having to attach new_property
explicitly to each new b-type object.