Shorter syntax for arrow function assignment

doodad-js Admin doodadjs at gmail.com
Tue Oct 24 20:44:02 UTC 2017


> On its way to being an edge case.

 

Not really because arrow functions are not re-bindable. They are always bound to a single object since their creation. They are meant to be used as “lambda” functions”, while providing a workaround for accessing properties of their “parent object” (ie the object referred by “this” at their creation). They are not simply a shortcut version of “function” like many people thinks.

 

 

From: Brian Blakely [mailto:anewpage.media at gmail.com] 
Sent: Tuesday, October 24, 2017 3:39 PM
To: Jordan Harband <ljharb at gmail.com>
Cc: dante federici <c.dante.federici at gmail.com>; es-discuss <es-discuss at mozilla.org>
Subject: Re: Re: Shorter syntax for arrow function assignment

 

> normal functions ... remain necessary for any use case where `this` needs to be determined at invocation time.

 

On its way to being an edge case.

 

On Tue, Oct 24, 2017 at 2:46 PM, Jordan Harband <ljharb at gmail.com <mailto:ljharb at gmail.com> > wrote:

"ES5 functions" - by which you mean, normal functions - are not "outmoded", they remain necessary for any use case where `this` needs to be determined at invocation time.

 

Nothing should ever produce an arrow function without `=>`; and exports assuming `const` is an interesting idea, but explicit > implicit, and "typing less" is simply not a goal worth optimizing for by itself.

 

On Tue, Oct 24, 2017 at 11:05 AM, Matthew Robb <matthewwrobb at gmail.com <mailto:matthewwrobb at gmail.com> > wrote:

There is practically no gain to suggest this syntax for arrows anyway as a module has no this binding you are creating a perpetually contextless function whereas using this shorthand syntax for a normal function makes some sense. You lose implicit return regardless.




 

- Matthew Robb

 

On Tue, Oct 24, 2017 at 1:47 PM, Andrea Giammarchi <andrea.giammarchi at gmail.com <mailto:andrea.giammarchi at gmail.com> > wrote:

> functions are already outmoded

 

I don't know where you come from but to me:

 

```js

// this ain't outmoded at all

const obj = {

  method() { return this === obj; }

};

 

// this ain't outmoded at all

class Any {

  method() { return this instanceof Any; }

}

```

 

And a module that provides mixins is definitively not outmoded at all

```js

export method() {

  return this !== undefined;

};

```

 

Omitting the arrow is everything but a syntax win here.

 

Regards

 

 

 

 

On Tue, Oct 24, 2017 at 2:32 PM, Brian Blakely <anewpage.media at gmail.com <mailto:anewpage.media at gmail.com> > wrote:

At current, sans an explicit assignment, the pragma `foo() {...}` should throw.

 

On Tue, Oct 24, 2017 at 1:26 PM, dante federici <c.dante.federici at gmail.com <mailto:c.dante.federici at gmail.com> > wrote:

Another annoying thing JS has to deal with is:

```

// implicitly 'var'

someVar = 10;

```

 

So, something like:

```

myFn() {

}

```

 

Would be considered as:

```

var myFn = function() {

}

```

 

with what semantics exist now. Not best practices, but what is currently interpreted in the language.

 

I'd 100% agree that, as a shorthand, this is nice:

```

myFn() { }

const myFn = () => {}

```

 

Which is what I mean. But I'm not the full implementation of JavaScript.

 

_______________________________________________
es-discuss mailing list
es-discuss at mozilla.org <mailto:es-discuss at mozilla.org> 
https://mail.mozilla.org/listinfo/es-discuss

 


_______________________________________________
es-discuss mailing list
es-discuss at mozilla.org <mailto:es-discuss at mozilla.org> 
https://mail.mozilla.org/listinfo/es-discuss

 


_______________________________________________
es-discuss mailing list
es-discuss at mozilla.org <mailto:es-discuss at mozilla.org> 
https://mail.mozilla.org/listinfo/es-discuss

 


_______________________________________________
es-discuss mailing list
es-discuss at mozilla.org <mailto:es-discuss at mozilla.org> 
https://mail.mozilla.org/listinfo/es-discuss

 


_______________________________________________
es-discuss mailing list
es-discuss at mozilla.org <mailto:es-discuss at mozilla.org> 
https://mail.mozilla.org/listinfo/es-discuss

 



---
This email has been checked for viruses by AVG.
http://www.avg.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20171024/8afbeca2/attachment-0001.html>


More information about the es-discuss mailing list