Is it possible to exclude certain fields from being included in the json string?
Here is some pseudo code
var x = {
x:0,
y:0,
divID:\"xyz
Another good solution: (requires underscore)
x.toJSON = function () {
return _.omit(this, [ "privateProperty1", "privateProperty2" ]);
};
The benefit of this solution is that anyone calling JSON.stringify on x will have correct results - you don't have to alter the JSON.stringify calls individually.
Non-underscore version:
x.toJSON = function () {
var result = {};
for (var x in this) {
if (x !== "privateProperty1" && x !== "privateProperty2") {
result[x] = this[x];
}
}
return result;
};