[thelist] prototype vs. adding method
Erik
gozz at gozz.com
Mon Apr 16 11:59:09 CDT 2001
Not sure if "referencing a method" would be the correct way of saying
it but ...
Someone tells me that someone told them that adding a prototype to an
object will use less RAM than if you make a function a method of that
object ... because the prototype is "stored only once" ... is this
true? Seems like it might be.
Example:
function showColor() {
alert(this.fur_color);
}
function Dog(fur_color) {
this.fur_color = fur_color;
this.showColor = showColor;
}
fido = new Dog('white');
spot = new Dog('brown');
VS:
function Dog(fur_color) {
this.fur_color = fur_color;
}
Dog.prototype.showColor = new Function { alert(this.fur_color) };
fido = new Dog('white');
spot = new Dog('brown');
--
I'm not sure if I got the prototype thing correct - I've always done
it the first way.
--
- Erik Mattheis
http://gozz.com/
(612) 827 3963
More information about the thelist
mailing list