Why JSON stringify and then parse is not working for this object. Is it works bad for objects with local variables?
function Task(description) {
var _description = description;
this.getDescription = function() {
return _description;
}
}
var task = new Task('wash car');
console.log(task.getDescription());
var json = JSON.stringify(task);
console.log(JSON.parse(json).getDescription());
JSON can't stringify functions (and it's not supposed to be able to).
But technically when you need to Stringify an object you should not need the functions. You can just pass the object as is within your application.
EDIT:
If what you need is the object to be stored locally then saving the functions along with it would not be a good idea anyway. What you can do is store the properties of the object and create a new instance when you retrieve it.