Subj : Re: outer visibility of nested functions To : netscape.public.mozilla.jseng From : =?ISO-8859-1?Q?Georg_Maa=DF?= Date : Sat Jan 10 2004 07:00 pm Brendan Eich wrote: > There is, as needed (whenever A is activated). js> function A() { function B() { print(this.name); } B.name = 'B'; B(); print(A.C); var C = 'C'; print(A.C + '\n'+ C); } js> A.C='c'; c js> A.C c js> A(); global c c C js> OK, I see. It is really independent for stuff like variables. js> function A() { function B() { print(this.name); } B(); A.B = 'boom'; } js> A.B(); A js> A(); global js> A.B boah js> A.B(); 103: TypeError: A.B is not a function js> A consequence of this extension is that calling A destroys the nested function B. Is it possible to make this extention switchable at runtime i.e. by implementing a boolean property __mapNestedFunctionsAsFunctionPorperties__ in the function prototype to enable or disable the extension as desired by the application? > That follows the usual this-binding rule: callee expression object > reference base. Yes, if B is called by the body of A, then this points to the global object. This is the only way to call B in NN4 -- Georg Maaß - bioshop.de D-76227 Karlsruhe, Westmarkstraße 82 HTML, XML / JavaScript, C++, Java, PHP, VB / CGI, JSP, ASP, ASP.net - The ultimate DHTML engine: http://gml-modul.sourceforge.net - http://sourceforge.net/projects/gml-modul .