Promises, , this
.
1:
this.method();
method
- , Foo
, this
, , this
this.method
. , Foo
.
2:
Promise.resolve().then(() => console.log('inline arrow function', this)); // Foo
- ES6, this
, . , this === Foo
, .
3:
Promise.resolve().then(normal); // window
Promise.resolve().then(arrow); // window
, , , this
, strict mode
.
4:
Promise.resolve().then(strictFunction); // undefined
strict mode
, , this
undefined.
5:
Promise.resolve().then(this.method); // undefined <-- why?
spec , :
ClassDeclaration ClassExpression .