Re: [JSON] Changing the class of an object after its construction
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Re: [JSON] Changing the class of an object after its construction

From: Raphael Jolivet <raphael.jolivetNO_SPAM_THANKS@laposte.net>
Date: Sun Nov 20 2005 - 19:02:41 CET

Thanks
"obj1.__proto__ = new myClass()" works well.

I though that "prototype" was a generic property to
manipulate the prototypes of objects, but you're right
It's only for constructors.

__proto___ was what I looked for.

Thanks

> Thomas 'PointedEars' Lahn wrote:
>
>
>>In fact, it MUST NOT work. `obj1' does not refer to a constructor
>>(i.e. a Function object), so that does not have a `prototype' property.
>>You are creating one with no intrinsic functionality here.
>>
>>To make the prototype chain work, you need another prototype.
>>I found two ways for this:
>>
>>a)
>>obj1.__proto__ = new myClass(); // JavaScript only, preserves properties
>
>
> or
>
> obj1.__proto__ = myClass.prototype;
>
>
> PointedEars
Received on Mon Nov 21 03:36:49 2005