function TestObj() { this.num = 1; } TestObj.prototype.setValue = function(val) { this.num = val; } TestObj.prototype.toJSON = function() { console.log("toJSON() called"); return Generic_toJSON("TestObj", this); } TestObj.fromJSON = function(value) { console.log("fromJSON() called"); return Generic_fromJSON(TestObj, value.data); } Reviver.constructors.TestObj = TestObj; var testObj = new TestObj(); //Terminal var post = function(input) { $("#terminal-input").before('