I have a ES6 class that contains a method with async.waterfall. Waterfall gets an array of functions as its first argument. So I do it this way:
class RequestLog {
mainMethod() {
async.waterfall([
this.method1,
this.method2,
this.method3
]);
}
method1(cb) {
console.log(this); // outputs null
cb();
}
}
But as noted above, in first function I nave this === null
. If it was anon function I'd write:
async.waterfall([ (cb) => { console.log(this) } ]);
but I want to have separated methods for code clarity.
So, how do I pass this
to named function inside a class?