3 ms·
I think .bind(this) could be added as a (more common?) alternative example to var self = this; Personally I'm most excited about the module system. It's by far
by kriro 11y ago
I think .bind(this) could be added as a (more common?) alternative example to var self = this;
Personally I'm most excited about the module system. It's by far the most confusing thing for our students (and hard to google since you end up going down the rabbit hole of build systems etc.)
- v413 11y agoWith the introduction of arrow function you won't need to use .bind(this) as arrow functions capture in their lexical scope the variables/keywords: this, arguments, super. e.g. setTimeout(function(){alert(this.a)}.bind(this)); becomes simply setTimeout(() => alert(this.a));
- kriro 11y agoYes, maybe my comment wasn't clear. I meant to say add ".bind(this)" as a case that is replaced by => just like "var self = this;" or (...)(); for that matter.
- pluma 11y agoThere is a proposal for a :: bind operator. 1. a unary :: operator for binding methods to their objects: `foo.then(::console.log)` 2. a binary :: operator for chaining: `x(a)::y(b)` (equivalent to `y.call(x(a), b)`)