Possible Duplicate:
Parse JSON String into a Particular Object Prototype in JavaScript
So I have a class defined like
function ThisClass (a,b,c) {
this.a = a;
this.b = b;
this.c = c;
}
ThisClass.prototype.a_method = function(param) {
//stuff
}
var instance = new MyClass(a,b,c);
var stringified = JSON.stringify(instance);
var parsed = JSON.parse(stringified);
When I stringify this and store it in a database it's all cool. However, when I parse it after retrieval, it loses its class type, so when viewing it after parsing in chrome's inspect tool, the object is shown as just a regular object, like instance: Object
instead of instance: MyClass
.
Because of this, the newly parsed variable parsed
does not have any of the prototype methods associated with it at instantiation. Any know how to do this, or if I'm doing it wrong?
Thanks!