Function declarations as statements

Michael Day mikeday at yeslogic.com
Thu Nov 11 16:48:22 PST 2010


Hi Brendan and Allen,

Thanks for the pointers.

> So for Harmony, we are reclaiming function in block (must be a direct child of a braced block) to bind a block-local name on block entry (so hoisting lives, but only to top of block -- so you can't emulate with var f = function ...).

If we implemented this behaviour now, I think that would be sufficient 
to make JQuery and Raphaël work. Here is an example from JQuery that is 
giving us trouble:

if (condition) {
     var val, props, ... ;

     function getWH() { ... this is the function ... }

     if ( elem.offsetWidth !== 0 ) {
         getWH();
     } else {
         jQuery.swap( elem, props, getWH );
     }

     return Math.max(0, Math.round(val));
}

The getWH() function is declared in the block and only used in the 
block, so if we hoisted the definition to the top of the block there 
would not be any problems with this usage.

Best regards,

Michael

-- 
Print XML with Prince!
http://www.princexml.com


More information about the es-discuss mailing list