` Mystery . wrote:
During the development of an ES6 web application, I came across a situation
where I wanted to bind 'this' of the outer function to a parameter of an
inner function

Use an arrow function for that:
```
function outer() {
    const inner = (_this = this) => {
        console.log(_this.a); // 1
    }
    inner.call({});
}
outer.call({a: 1});

In the latest Firefox, the above script prints 'undefined'. This seems
pretty counter-intuitive, and it also fails when I try to pass 'this.a' as
default value for the parameter of the inner function. I wonder if this is
an intended behavior? Thanks in advance.

Yes, it is intended, and pretty intuitive - default initialisers are evaluated in the scope of the called function, at the call - they're not values that are computed at the time of the definition of the function.

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

Reply via email to