Friday, October 06, 2006

Native object serialization in JavaScript (mozilla only)

Check it out:
a = new Object();
a.name = "daniel";
b = new Object();
b.a =a;
b.createDate = new Date();
b.index= 4;
document.write(b.toSource())

results in :
({a:{name:"daniel"}, createDate:(new Date(1160162836203)), index:4})

even more, it supports circular reffrencing check out the next example

a = new Object();
b = new Object();
c = new Object();
c.b = b;
c.a = a;
a.b= b;
b.a =a;
b.c = c;
document.write(b.toSource())
the result will be:
#1={a:#2={b:#1#}, c:{b:#1#, a:#2#}}

there are some js libraries that mock that feature in ie also ,
more to come.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home