I think this one is deprecated. It was removed for a short period of time in FF 3.1, then restored in a slightly different form:
Removed in: https://bugzilla.mozilla.org/show_bug.cgi?id=442333 Caused a bug in: https://bugzilla.mozilla.org/show_bug.cgi?id=457068 Restored (in a different form) in: https://bugzilla.mozilla.org/show_bug.cgi?id=446026 I believe the new form lets you clobber the scope chain during (but not beyond) the eval() call, somewhat like Firefox's evalInSandbox() for chrome code. On 5-Mar-09, at 3:20 PM, Ray Cromwell wrote: > > There is also the magic eval() method in Firefox which allows an > additional parameter to be specified as the context (see > http://ajaxian.com/archives/evalfooa-objfn-how-you-arent-private-in-firefox) > > e.g. > > eval(script, $wnd); > > -Ray > > > On Thu, Mar 5, 2009 at 2:10 PM, Matt Mastracci > <[email protected]> wrote: >> >> Lex, >> >> Have you tried using the string constructor for Function()? I >> believe >> that it creates a function whose lexical scope is bound to the top- >> level, no matter where it is executed. >> >> <script> >> var a = 2; >> >> function x() { >> var a = 3; >> return new Function("alert(a); a = 4;"); >> } >> >> x()(); >> alert(a); >> >> function y() { >> var a = 10; >> x()(); >> } >> y(); >> </script> >> >> This alerts "2", "4", "4" in Firefox, Safari, Opera and IE6. >> >> On 5-Mar-09, at 1:19 PM, Lex Spoon wrote: >> >>> >>> For possible amusement, I spent half a day yesterday spelunking into >>> the world of various ways to install code in a web browser. Details >>> are here: >>> >>> http://lexspoon.blogspot.com/2009/03/many-scopes-of-javascripts-eval.html >>> >>> >>> My initial idea to use window.eval turns out to be terribly >>> non-portable: it only evaluates at window scope on Firefox. >>> Instead, >>> I'm thinking to use the following code to install newly downloaded >>> code: >>> >>> if (window.execScript) { >>> window.execScript(script) >>> } else { >>> var tag = document.createElement("script") >>> tag.type = "text/javascript" >>> tag.text = script >>> document.getElementsByTagName("head").item(0).appendChild(tag) >>> } >>> >>> >>> The first branch is for window.execScript, which is available on IE >>> and, of all things, Chrome. They are such similar browsers, you >>> know. >>> The second branch works on all browsers, but it's ugly enough that I >>> didn't want it to be used all the time. Maybe that's silly, and >>> only >>> the second branch should always be used. >>> >>> Any thoughts or better ideas? >>> >>> Lex >>> >>>> >> >> >>> >> > > > --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/Google-Web-Toolkit-Contributors -~----------~----~----~----~------~----~------~--~---
