Subj : Re: Weird nested function behavior in IE To : Ryan Breen From : Igor Bukanov Date : Tue Nov 02 2004 11:42 pm Ryan Breen wrote: > The following: > > if(true) > { > outer.prototype.inner=hello_world; > function outer() > { > this.inner(); > } > > function hello_world() > { > alert("HI"); > } > > var hold_me =new outer(); > } > > works in IE but fails in Firefox or Rhino. In Rhino, the error is > that 'outer' is evaluated as a FUNCTION_EXPRESSION_STATEMENT rather > than a FUNCTION_STATEMENT but fn.itsClosure is null. Has anyone seen > anything like this before? Note that this code does not confirm to ECMAScript standard since ECMAScript allows function statements only at the top level of script or function. Now MS JScript and SpiderMonkey/Rhino extends that allows to define function statements anywhere were a JS statement is allowed, but the semantics is different: In JScript all such function statements are treated in the same way and effectively evaluated at the start of script/function so you can refer the functions by names right away. In SM/Rhino such functions are defined only when the corresponding code reaches the point of the "extended function statement" declaration which allows to have a conditional compilation. For example given: if (condition) { function test1() { } } function test2() { } then JScript would always define test1 even if condition is false while SM/Rhino would define it only when condition is true. To make you example to work move hello_world()/outer to the beginning of the if block. Regards, Igor .