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

On Mon, Mar 9, 2009 at 8:35 AM, Jeff Watkins <[email protected]> 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
_______________________________________________
Es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to