Is there any way that I can pass a function as a json string (conversion with JSON.stringify), send it to another function, parse the json and then execute the function that was in the json? I am using jquery and javascript.
Yes, you can.
"There is no way to store functions in JSON." — That isn't true. That just shows there is no native function data type. A function could be expressed as a string.
Yes, you can. There are tons of ways to do it.
And there is no need to use the "evil" eval function (please yahoogle why it should be avoided) as pointed out here: http://javascript.about.com/library/bleval.htm
var tmpFunc = new Function(codeToRun); tmpFunc();
Whether it was JSON at any stage should be irrelevant.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With