name anonymous functions on property assignments

Bradley Meck bradley.meck at gmail.com
Tue Jul 28 19:40:15 UTC 2015


a big concern for me is what to do about functions being passed around:

```
var a = {};
a.foo = function () {}
// .name would be "foo"
var b = {};
b.bar = a.foo;
// .name would be "bar"
```

or

```
function doThing(callback) {
   var async = {};
   async.fn = callback;
   // ...
}
doThing(()=>{})
// what is .name?
```

Most of my functions are declared separately from where they are attached
to functions. I think naming them is fine, but this could get confusing
about the rules of when / which functions are named.


On Tue, Jul 28, 2015 at 1:13 PM, <a.d.bergi at web.de> wrote:

> > Just saying that an exposed property name is a different (and
> potentially more broadly exploitable) capability than exposing a local
> variable name.
> >
> > TC39 reached consensus on automatically assigning the `name` property
> for expression forms like:
> >       Identifier = FunctionExpression
> > and so it is part of ES2015.  We did not have consensus on doing the
> same for:
> >       MemberExpression.IdentifierName = FunctionExpression
> > or
> >       MemberExpression[Expression] = FunctionExpression
> > so it is not part of ES2015. There were various objections that would
> have to be overcome before we could adopt that.
>
> Ah, that's what I wanted to know. Can you detail these objections, please?
> Or link to the TC39 notes where these were discussed?
>
> I see that method names are more capable than local variable names, but
> aren't we already naming methods by default everywhere else? Even those
> with computed keys?
> To me, there is not much difference between
>
>     let o = {
>         method: () => {…}
>     };
>
> and
>
>     let o = {};
>     o.method = () => {…};
>
> yet the first function gets a name while the second one doesn't.
>
>  Bergi
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150728/d046282e/attachment.html>


More information about the es-discuss mailing list