On 23/06/06, Gregory Hill <[EMAIL PROTECTED]> wrote:
Modifying the prototype will not modify all
of the instances (according to Andrew, haven't verified it or anything, but
I think he's right).
Actually, Ryan is right. I did a test and If you modify a prototype
object, existing instances of an object are updated. but you have to
do it via the constructor function object not an instance. Which I
think was confusing the original poster, Sam.
But you cannot change an objects prototype to another prototype.
here's the test (using Firefox with firebug extension for the log):
function obj(name) {
this.name = name;
}
obj.prototype.p = "x";
obj.prototype.x = function(){ return this.p };
var obj1 = new obj('1');
var obj2 = new obj('2');
console.log(obj1.name + ":" + obj1.x());
console.log(obj2.name + ":" + obj2.x());
console.log("switch...");
obj.prototype.p = "kk";
console.log(obj1.name + ":" + obj1.x());
console.log(obj2.name + ":" + obj2.x());
the output:
1:x
2:x
switch...
1:kk
2:kk
--
Andrew Tetlaw
htp://tetlaw.id.au
_______________________________________________
Rails-spinoffs mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs