Categories
javascript node.js

How to serialize an object in JavaScript?

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)