On Jul 28, 2008, at 3:22 PM, Michael Haufe wrote:
function foo () { return 'global'; }

class bar {
   function foo () { return 'local'; }

   function zot () {
     // How can I call the global foo from here?
     without (this) { foo(); }
   }
}

It's the same as if you lambda-coded the above (here shown in JS1.8 [Firefox 3], note the expression closures):

function bar() {
  function foo() 'local';
  function zot() global.foo();
}
function foo() 'global';

This example uses ES4's global synonym for the global object, but you could capture this in a global var at top level:

var global = this;
print(new bar().zot()); // print 'global'

in ES3 or JS1.8 to get the same effect.

You could use window["foo"](); or whatever the global object is named in the environment

No need to quote and bracket, of course -- window.foo() is fine too.

/be

_______________________________________________
Es4-discuss mailing list
Es4-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es4-discuss

Reply via email to