You are saying that since I ran them in firebug continuously, the variables
were initialized for both functions. To run them as written, they would
have to be in different pages. Got it. Thanks.
On Monday, October 22, 2012 9:57:27 PM UTC-2, molipha wrote:
>
> Hi,
>
> I'm reading Mark Obcena's Pro Javascript with mootools and have found some
> code that doesn't seem to agree with what he's written. When I run the
> following code in Firebug, I get myFn defined in all scopes. Any comments?
>
> var myFn = function(){
> // reference the function
> console.log(typeof myFn);
> };
> myFn(); // 'function'
>
> // global scope
> var createFn = function(){
> // result function
> return function(){
> console.log(typeof myFn);
> };
> };
>
> // different scope
> (function(){
> // put the result function of `createFn`
> // into a local variable
> var myFn = createFn();
> // check if reference is available
> myFn(); // 'undefined' - NO! This shows up as defined!
> })();
>
>