I created custom stringify method to stringify function as follow
var myStringify=function (obj) {
return JSON.stringify(obj, function (key, value) {
if (value instanceof Function || typeof value == 'function') {
return value.toString();
}
return value;
});
}
But when I have no idea about parsing string function into function object. Here is my example
var parsed=JSON.parse(jsonString);
After processing JSON.parse function, I got following
parsed.run field has string of function
console.log(parsed.run) // output is "function(){console.log('foo');}"
I want this function string back into property of parsed object,
{run:"function(){console.log('foo');}"}
into
{run:function(){console.log('foo');}}
how should I do?
"function(){console.log('foo');}"is not a valid JSON..eval()?