shorthand vs longhand
JavaScript
class TestClass {
doSomething(){
return Promise.resolve(this.someFunction('hello'))
}
someFunction( testVar ){
return testVar;
}
}
let instance = new TestClass();
// throws error
Promise.resolve()
.then(instance.doSomething)
.then(console.log)
.catch(console.error);
// works
Promise.resolve()
.then(() => instance.doSomething())
.then(console.log);
// works
Promise.resolve()
.then(function(){return instance.doSomething()})
.then(console.log);
// works
function someFunc(){
return instance.doSomething();
}
Promise.resolve()
.then(someFunc)
.then(console.log);