"Pretty" function expression names

Brendan Eich brendan at mozilla.com
Sun May 10 16:35:13 PDT 2009


Sorry, your use of closure was unclear enough that I went with door #1  
(mutating a closure by giving it an intrinsic name). I did wonder if  
you meant door #2 (creating an inner scope function other than by  
eval), and you did, so let's deal with that:

On May 10, 2009, at 4:20 PM, Laurens Holst wrote:

> …by using a function constructor:
>
> function a() {
>   var x = 1;
>   return Function.create('y', ['z'], {x: x}, 'return x+z;');
> }
> var y = a();
> y(2);

No, that would not be nice. Consider the case where the created  
function mutates x. Consider obfuscation or infeasible-to-analysis  
arbitrary computation of the string parameters to Function.create, or  
even of the reference to Function.create that function a calls.

Only eval has to exact the stupid-taxes here. Let's not have another  
set of tax-hikes.


> Or perhaps you would rather want to pass a reference to the local  
> scope (‘arguments’?) instead of an individual variables.

Write a closure, or pay the eval tax. Why should Function.create make  
inner-scope closures? What is the real-world use case that can't use  
eval?

/be


More information about the es-discuss mailing list