I have created a new class using MooTools.
My class looks like this
Updated:
var c=new Class({
a:'',
b:'',
c:'',
d:'',
initialize:function(ee){
this.e=ee;
},
buildJSON:function()
{
var cInstance=new c(this.e);
cInstance.a=this.a;
cInstance.b=this.b;
cInstance.c=this.c;
cInstance.d=this.d;
return (JSON.encode(cInstance));
}
});
var x=new c("action");
x.a="Hello a";
x.b="Hello b";
x.c="Hello c";
x.d="Hello d";
alert (x.buildJSON());
This is pretty a straightforward class. Now if you try it, there is an extra key on the JSON:
"$caller":null,
"caller":null
$callerandcallerare both properties added by MooTools Class.They exist to assist in the use of the
parentmethod. You should clone the object and clean out the unnecessary properties before usingJSON.encodeon the class instance.You could clone
thisand delete$callerandcallerfrom the clone.