func=function() {foo=true}
alert(JSON.stringify(func));
alerts "undefined"
obj={foo: true}
alert (JSON.stringify(obj));
alerts: "{foo: true}"
Why is this? As far as I understand JSON.stringify() converts an object to a json string, but I notice this doenst work for a "function object".
Btw searching for "function object" is hell in search engine land, because the only results I get out of google are about how objects are functions and functions are objects, but little about an actual function object.
"The Function constructor creates a new Function object. In JavaScript every function is actually a Function object." https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function
"Ok google: so every javascript function is an object, and every object is an function..." its the same, but it acts differenlty? I dont get it. So I am turning to stackoverflow. Can anyone enlighten me and explain why JSON.stringify(function() {foo=true}) does not work?
(ps. my goal is to turn function() {foo=true} into "function() {foo=true}" I am not looking for a workaround. I want to know why it doenst work to convert the function object to (json) string.