On Mar 10, 2009, at 8:29 PM, Garrett Smith wrote:
[...]
Maciej' Function.create proposal:-
Function.create("[Foo bar]", "param1", "param2", "code(); goes();
here();");
- uses strings to create a function. Escaping strings in strings is
awkward to read and write. Refactoring a function into strings to
arguments to Function.create would be tedious and error-prone.
Especiall if the soure already contains strings in strings (html = "<p
id='p'>p<\/p>". Using with strings to build functions cumbersome.
Agreed. That would be messy.
Eval uses the calling context's scope. I do not know what the scope
would be for a function created with Function.create. To use the
calling context's scope would seem to be not secure. However, it would
seem necessary to wrap a function.
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.
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?
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?
--
Juriy Zaytsev
Core developer, Prototype.js
[email protected]
_______________________________________________
Es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss