var a = function() { return arguments.callee.b }
a.b = 'foo';
a(); // returns 'foo'
a.toSource(); // returns '(function () {return arguments.callee.b;})'
b is a part of a and cannot be found in the result of toSource().
( tested with firefox 1.5.0.1 )
Franck.
Yes, toSource (uneval is the global function to use on any value to
produce a string that, when eval'ed, results in an isomorphic or equal
value) is not perfect. There is no syntax, in particular, for a lambda
with expandos added. Perhaps something like
((__tmp = function () { return arguments.callee.b; }).b = "foo", __tmp)
but JS has no such expression-scoped variables. This is fodder for deep
thinking on better syntax and more uniform notation, for Edition 4 or a
later ECMA iteration (we can experiment in advance in SpiderMonkey, so
don't take these words as discouraging).
/be
((function () { function a() { return arguments.callee.b; } a.b="foo";
return a; })())
?
Mike
As I pointed out to shaver, although lambdas are what pass for blocks or
let-expressions in JS, they also create a second function object, which
is costly enough that I wouldn't use them here.
It seems to me toSource/uneval is misconceived. What most people want
is not round-tripping, hi-fi serialization, but a programmer friendly
string representation (Pythonic repr). Not all bits must be included,
and the string returned need not eval without error.
Of course, SpiderMonkey is committed to compatibility, so we won't be
changing toSource except to fix bugs and elaborate compatibly (that is,
eval-ably). So suggestions for more universal result syntax are still
welcome.
Comments on repr desirability in JS (MochiKit rolls its own as it must)
also welcome.
/be
As I pointed out to shaver, although lambdas are what pass for blocks or