self functions
Frankie Bagnardi
f.bagnardi at gmail.com
Tue Jul 28 06:09:24 UTC 2015
Aside from returning `this` you're suggesting an alternate syntax for arrow
functions? I don't see any value here.
More importantly, the syntax is ambiguous for unnamed functions.
```js
// already valid syntax
var self = function self(){};
```
On Mon, Jul 27, 2015 at 7:06 PM, Bucaran <jbucaran at me.com> wrote:
> Add a `self` decorator to functions that makes them return `this` by
> default.
>
> export function self myMethod () {
> // return this by default
> }
>
> This decorator could be used to make any function bound to the current
> scope `this` as well so:
>
> func(function self () { // this is bound to my dad’s scope
> })
>
> Would be roughly equivalent to:
>
> func(() => { // this is bound to my dad’s scope })
>
> Although I personally would favor the arrow function syntax, the `self`
> decorator could be
> used to optimize binding generators, so instead of:
>
> func(function* () { }.bind(this))
>
> One could write:
>
> func(function self* () { })
>
> Similary it could be used in promise handlers, so instead of:
>
> new Promise(function (resolve, reject) { }.bind(this))
>
> One could write:
>
> new Promise(function self (resolve, reject) { })
>
> It would be even sweeter if you didn’t need to specify the keyword
> function when writing `self` functions:
>
> new Promise(self (resolve, reject) { })
> _______________________________________________
> 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/20150727/6f0c624c/attachment-0001.html>
More information about the es-discuss
mailing list