In IE 11, calling Stringify on my objects is not recursively calling toJson on all object in the tree. I have a custom toJson function
Object.prototype.toJSON = function() {
if (!(this.constructor.name == "Array")) {
if (JSON._serialized[this._id]) {
if (this.material) {
return {
name: this.name,
material: this.material
};
} else {
return { referenceId: this._id };
}
}
var json = this.toJSONProperties();
json._id = this._id;
json._runID = this._runID;
json._className = this.constructor.name;
JSON._serialized[this._id] = true;
return json;
} else {
return this;
}
}
This works in chrome, firefox and safari, but in IE 11 this toJson function only gets called on the top level object when I call var json = JSON.stringify(object);
The idea im working with is have toJson be a generic function on all classes, then have var json = this.toJSONProperties(); on the specific classes i want to convert. Any Ideas why this only fails in IE?
Update
I fixed the problem. It turns out that this.constructor.name doesn't work in IE.
Changing it to this.constructor.toString().match(/function (.{1,})\(/)[1] fixes the error.
toJSONmethod, it should be called and no other attribute should be taken in considerationDeck.prototype.toJSONProperties = function() { return { _components: this._components } };