Fun impossible Firefox JS challenge

Brendan Eich brendan at mozilla.org
Fri Apr 13 07:46:37 PDT 2012


Latest SpiderMonkey allows just

!function(){

   function true(){print('Call me');};

   function::true();

}();

as the solution. This shows extensions from E4X (namespaces, extended 
with the built-in 'function::' magic) and ES4 (allowing reserved 
identifiers after 'function').

Extensions are allowed by Clause 16 of ECMA-262. But perhaps there's an 
explicit prohibition on one or both of these?

Anyway they are demons from the second age, and they're going away.

/be

gaz Heyes wrote:
> Ok here is my solution:
>
> with(arguments.callee)function::['true']()
>
> So initially I thought the with statement was required to switch the 
> context of "function::" but this also worked:
> with(1+1)function::['true']()
>
> However this doesn't work on Firefox 11:
> function::['true']()
>
> So what I think happens is Firefox looks for the true function in the 
> window object then can't find it so falls back to the parent object 
> with is the current anon function.
>
> It can also be called using eval as eval is in the current scope:
> eval("function::['true']()");
>
> I guess the shortest you can possibly make it is:
> with(1)function::true()
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss


More information about the es-discuss mailing list