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: John G Harris <john@nospam.demon.co.uk>
Date: Sun Nov 20 2005 - 18:30:37 CET

In article <ux%ff.1569$gC1.880@nntpserver.swip.net>, Raphael Jolivet
<raphael.jolivetNO_SPAM_THANKS@laposte.net> writes
>
>Hello there,
>
>I have a bunch of objects that I store in a text file (to store
>preferences),
>after having serialized them with JSON.
>
>Let's say I have my object :
>
>obj1 = {
> a : 1
> b : 2
>}
>
>Then, serialized in a string :
>"{a : 1, b:2}";
>
>To get the object back (when loading it from prefrences), i do almost :
>obj1 = eval("[a:1,b:2");
>
>Ok, my object is now back, but actually, the source object was
>a 'myClass' object, with lot of cool methods in it.
  <snip>

Why not have two constructor functions with their prototype properties
the same.

When you make an object the first time you do
  new Thing( <params> );
When you deserialise it you do
  new InThing( <string> );

If Thing and InThing do what's needed you won't be able to tell the
difference between the two objects.

  John

-- 
John Harris
Received on Mon Nov 21 03:36:48 2005