onchange event

Juriy Zaytsev kangax at gmail.com
Mon Mar 9 11:40:27 PDT 2009


On Mar 9, 2009, at 2:06 PM, Garrett Smith wrote:

> On Mon, Mar 9, 2009 at 8:35 AM, Jeff Watkins <watkins at apple.com>  
> wrote:
>> Garrett, I gave a specific use case for why I'd like to be able to  
>> specify
>> the name on an anonymous function: wrapping an existing function  
>> with pre-
>> or post-call behaviour.
>
> I think I get it.
>
> It seems like just giving the function a name (not *anonymous*) would
> fulfill that need.
>
> Example:-
>
> <script>
> var getX = (function(){
>  var x = 10;
>  function getX() {
>    return x;
>  }
>  return getX;
> })();
>
> document.write(getX.name + ": " + getX());
> </script>

It is sometimes unfortunate that Function's Identifier can not be set  
from a string value, without resorting to `eval`. Descriptive  
Identifier's make debugging easier. A simple example of some kind of  
constructor creation facility shows what I mean:

var Class = {
   create: function(name) {
     var fn = eval('(function ' + name + '(){})');
     // set up inheritance, etc.
     return fn;
   }
}

Class.create('Person'); // Person()

I think it could be beneficial if `Function.create` would allow for  
such control.

[...]

-- 
Juriy Zaytsev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20090309/4a781da4/attachment.html>


More information about the Es-discuss mailing list