But, how can you create an instance of a class without knowing the constructor's name? It's much more likely you know the constructor's name than the name of any given instance.

But, try this... (not sure if its works but worth a shot if you need it)...

oMyObj5.constructor.prototype.bSwitch = true;

On 6/21/06, Sam <[EMAIL PROTECTED]> wrote:
Nope... in fact this is one of the "dynamic" benefits of a prototype based object system.  Changing the prototype of the "class" function (the function from which the other references are constructed), changes the state of all instances automatically.

MyObject.prototype.bSwitch = true; is the correct way to achieve what you are looking for. Why would you want to do this by using an instance of said class? It seems to me you'd _want_ to _not_ have to know what instances are floating around in your application, so the "class" function's prototype is the natural place to make this change. In other words, you have 10 widgets and a couple of flibbets, maybe a few woozles on your page, each of them possibly containing N instances of MyObject. Why would you want to have to know the name of one of those instances to set this switch across all of them... see my point?

After declaring the Class, I've never had to mess with a class before.  This takes some getting used to, and it seems strange that I can't reference the class / constructor from an instance without knowing the constructor's name???
 
I was under a mistaken assumption that
 
oMyObj1.prototype
 
would move up the prototype chain to reach the constructor function MyObject. 
 
If
 
var oMyObj5 = new MyObject();
 
doesn't it make sense that there should be a pointer on the oMyObj5 object which points back to the constructor function?  Without __proto__, there's no way to reach back to the constructor without knowing the constructor's name?
 
Sam
 

_______________________________________________
Rails-spinoffs mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs



_______________________________________________
Rails-spinoffs mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs

Reply via email to