On Aug 17, 6:33 pm, Matt Kruse <[EMAIL PROTECTED]> wrote: > On Aug 17, 11:11 am, Stephan Beal <[EMAIL PROTECTED]> wrote: > > i think this would be counter-intuitive. If i pass a string to a > > function and know that it will be executed, i would expect the string > > to be eval()'d, not run in a Function object, and those evaluate their > > code with different scoping rules. > > How so? Both are run in the context of the global object, are they > not?
According to the rhino book: "A last, very important point about the Function() constructor is that the funcions is creates do not use lexical scoping; insteawd, they are always compiled as if they were top-level functions..." That alone completely rules out their use for many use-cases as event handlers, which often want access to variables from their containing scope. > > Shouldn't that be (new Function(f)) instead of (Function(f))? > > Same diff, but shorter. i don't think those are the same, as (Function(...)) is not creating a new object, but theoretically its working directly on the prototype object. Maybe i'm wrong on this, but it looks suspicious to me. > > IMO this change would be far more complex that it seems because, for > > example, the following no longer applies: > > if( typeof f == "function" ) { ... } > > Why would you want to do this, anyway? When a function takes multiple argument types you have to check what those types are. That gets more complicated with two distinctly different ways of having functions. > Once it gets past the initial call to click() or whatever, it is a > function all the way down. > If you define a new Function, the resulting object is typeof > 'function'. ~> SpiderApe -e "x=new Function('1');print(typeof x);" function You're right - i wasn't aware of that. > There would be no visible effect anywhere else in plugins, etc. i said earlier (in two posts) that the call syntax is different, but that is apparently incorrect: ~> SpiderApe -e "x=new Function('print(1);');x();" 1 JS apparently offers special-case handling of this type. > >The cascade of side-effects is enormous. > > I don't see any side-effect at all, but I may of course be wrong ;) My apologies - i grossly overstated the side-effects (/me smacks forehead). But the scoping issue is still critical, as event handlers often need access to variables from their contained scope, and that apparently can't be done with Function objects.