On Tue, Mar 10, 2009 at 6:22 PM, Juriy Zaytsev <kangax at gmail.com> wrote:
>> On Mar 10, 2009, at 8:29 PM, Garrett Smith wrote:
> [...]
[...]
> Possible alternative:-
> Function.create( name, fun[, context] );
>> I can't think of a better alternative at the moment. What's weird about such
> notation though, is that `Function.create` doesn't quite fit the description
> any longer. Function object is being created during evaluation, *before*
> it's being passed to `Function.create` as the last argument. What
> `Function.create` does is merely setting/modifying an Identifier on a given
> function. It seems that `Function.setName` (or some such) would convey an
> intent better.
Sorry, no, that was not the intent. The intent would be to create a
new function object based on |fun|, using the same scope.
> Function.setName('name', function(){ ... });
> On a side note, what happens when you pass a function with already existing
> identifier? Would it be overwritten or left intact?
Returns a new function, |fun| is unchanged.
> Function.create('foo', function bar(){ });
> And finally, I assume that some kind of error would be thrown if `name`
> string can not be parsed as an identifier?
Sounds reasonable to me, though Maciej' proposal seems to attemp just that:-
Function.create("[Foo bar]", "param1", "param2", "code(); goes(); here();");
would the identifier be [Foo bar]?
That would result in a conformance clash with toString (which is
spec'd in 3.0 to return a FunctionDeclaration, which implementations
don't do with an anonymous function).
Garrett