> I can't remember the example I used in the meeting, but one example is a 
> recursive function:
> 
>  class Chicken extends Weapon {
>    constructor(length, elasticity, initialVelocity) {
>      this.length = length;
>      this.elasticity = elasticity;
>      this.initialVelocity = initialVelocity;
> 
>      var self = this;
> 
>      function animate() {
>        ...
>        self.velocity
>        self.elasticity
>        self.length
>        ...
>        setTimeout(animate, n);
>        ...
>      }
> 
>      ...
>    }
>  }

I don’t see the problem. Would the following code not work?

```js
const animate = () => {
    ...
    this.velocity
    this.elasticity
    this.length
    ...
    setTimeout(animate, n);
    ...
};
```

> The point I was making in the meeting was that arrow functions are a 
> syntactic convenience for a common case, not a general-purpose replacement 
> for all functions that need to refer to an outer this-binding. They are not 
> general-purpose because they don't support all the features of longhand 
> functions.

Given that function names will probably be inferred by engines, only hoisting 
would be an advantage of a hypothetical longhand function with lexical `this`(?)

What I’m worried about is conceptual simplicity. I like function declarations 
and prefer them to function expressions, but recently did a small survey on 
Twitter and was surprised to find out that the majority of people prefer var + 
function expression to a function declaration, because then there is only a 
single kind of function definition.

Axel

-- 
Dr. Axel Rauschmayer
[email protected]

home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com



_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to