by lambdapie · 11y ago · 0 comments
LJSON.stringify(function(v) { return v; })
evaluates to the string (function(v0){return v0})
While LJSON.stringify(function(v) { return v(null) } )
Evaluates to the string (function(v0){return "v0"})
In the latter case, v(null) was able to examine the variable that stringify injects into the function. In this case, v(null) is the name of the injected variable.For example
LJSON.stringify(function(v) { if (v == 0) { return "zero"; } else { return "one"; } })
Evaluates to the string (function(v0){return "one"})
The only way to avoid both these issues, is to inspect the code of a function f using f.toString(). However you would need to consider the scope where f was defined.Thanks for figuring that out!