Skip to content

Instantly share code, notes, and snippets.

@abozhilov
Created February 27, 2012 18:16
Show Gist options
  • Save abozhilov/1925932 to your computer and use it in GitHub Desktop.
Save abozhilov/1925932 to your computer and use it in GitHub Desktop.
JSON.stringify reflection
function StatNode() {
this.dns = 0;
this.connect = 0;
this.first = 0;
this.last = 0;
}
StatNode.prototype.setParam = function (param, value) {
//...
};
StatNode.prototype.toJSON = function () {
return JSON.stringify({
dns : this.dns,
connect : this.connect,
first : this.first,
last : this.last
});
};
function Statistic() {
this.stat = [];
}
Statistic.prototype.pushNode = function (statNode) {
this.stat.push(statNode);
};
Statistic.prototype.toJSON = function () {
return JSON.stringify(this.stat);
};
var stat = new Statistic();
stat.pushNode(new StatNode());
stat.pushNode(new StatNode());
stat.pushNode(new StatNode());
stat.pushNode(new StatNode());
console.log(JSON.stringify(stat));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment