Good point about, POLA.  Of course, arguments.callee is writable (and 
deletable)  so it could be removed or modified before passing it on.

POLA is also the reason for preferring use of the Function constructor over 
eval. The function constructor is essentially a constrained eval that carries 
less authority.  In particular, in non-strict mode eval can create bindings in 
the Declaration Environment of its caller (or the Global Environment) and in 
either mode it can modify any in scope bindings.  More generally, eval can 
execute arbitrary code and have arbitrary side-effects. None of that applies to 
calling the Function constructor.  Those seem like really good reasons to 
encourage use of the Function constructor instead of eval, where possible.

Allen

From: Mark S. Miller [mailto:erig...@google.com]
Sent: Tuesday, March 10, 2009 9:03 AM
To: Allen Wirfs-Brock
Cc: Douglas Crockford; David-Sarah Hopwood; es-discuss@mozilla.org
Subject: Re: arguments.callee and strict mode

On Tue, Mar 10, 2009 at 8:52 AM, Allen Wirfs-Brock 
<allen.wirfs-br...@microsoft.com<mailto:allen.wirfs-br...@microsoft.com>> wrote:

In reviewing the spec. I was reminded that arguments.callee is disabled within 
strict mode functions.  Do you recall why you wanted to do this, other than 
general dislike of arguments.
POLA. A frequent and sensible pattern of use for "arguments" is to pass it 
along to someone else to give them access to your arguments list. In typical 
usage, it is not usually intended or desired to thereby give them access to the 
function itself, not to give them the ability to alter your parameter variables 
(hence the lack of joining).



It occurs to me, that using arguments.callee is the only way  to express 
recursion within a function created using the Function constructor and that use 
of the Function constructor (rather than eval) should probably be encouraged 
for dynamically constructing functions from source code.
Why? I was thinking exactly the opposite: That we should encourage use of 
eval() rather than the Function constructor for dynamic creation of functions.


--
   Cheers,
   --MarkM
_______________________________________________
Es-discuss mailing list
Es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to