How to serialize an object in JavaScript?


Question

For example I have class:

function Test() {
}

Test.prototype = {
    'setTest' : function(test) {
        this.test = test;
    }
}
var test = new Test();
Test.setTest('test');

I want to save object test in database. How to serialize object test to string? (methods, variables, etc)

1
9
12/31/2015 3:49:41 PM

Simple with json

JSON.stringify( test );
11
8/1/2012 1:33:27 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon