Created
February 27, 2012 18:16
-
-
Save abozhilov/1925932 to your computer and use it in GitHub Desktop.
JSON.stringify reflection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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