Lets say I want to assign a class method as a callback, which is better? By better, I really mean for style & readability.
const Foo = class {
/** @param {!Promise} */
optionOne(theirPromise) {
theirPromise(this.myHandler_.bind(this));
}
/** @param {!Promise} */
optionTwo(theirPromise) {
theirPromise(() => this.myHandler_());
}
/** @private */
myHandler_() {
// Do something classy
}
};
I read the arrow function call as cleaner in this case, but if there are a bunch of parameters in the callback, it starts to get silly:
addCallback((a, b, c, d, e, f) => this.myHandler_(a, b, c, d, e, f))
I see the penalty of wrapping in a function, memory mostly, assuming the compiler doesn't trim the call away.