Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.)



With 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));


Yes, 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.


There 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)`)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: