Those are two separate examples, so you shouldn't execute them at the same
time.
>From page 29 a section about scoping starts, which explains this more.

On Wed, Oct 24, 2012 at 2:27 PM, molipha <[email protected]> wrote:

> Hi,
>
> The example starts on the bottom of page 15. Thanks for your analysis but
> actually the code works as I would expect. What confuses me is that Mark
> maintains that the last call to myFn() in the inline function should return
> 'undefined'. This is not correct, or I am doing something wrong.
>
> Appreciate your input.
>
>
> 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!
>> })();
>>
>>

Reply via email to