Function constructor create named function expression?

Asen Bozhilov asen.bozhilov at gmail.com
Wed Jun 30 02:38:24 PDT 2010


Function constructor is considered as bad practice by many JS gurus,
but sometimes I use Function constructor for shorter scope chain. The
problem in ES5 strict mode come when I want recursive call of
function, which is created by Function constructor. I can not use
`arguments.callee` and Function constructor does not provide way to
create NFE. I would like to see Function constructor, which can
create:

- NamedFunctionExpression
- Setter for [[Scope]] internal property

For example:

var F = Function({
    name : 'NFE',
    arguments : ['arg1', 'arg2', 'argN'],
    scope : {a : 10, b : 20},
    body  : "print(typeof NFE); print(a + b);"
});

F.length;
-> 3

F();
-> function
-> 30


More information about the es-discuss mailing list