This project is read-only.

Arrow functions currying "this"

Topics: Language Specification
Jan 8, 2013 at 10:57 PM

Arrow functions are great for callbacks, in that they help keep "this" lexically scoped. However, there are a lot of JavaScript libraries that use "this" as the current element. (Example: d3.selectAll("g.chart").each())

This leads to the situation where you either:

a) revert back to manually creating your closure via var _this = this;

b) use a currying function to provide the caller's "this" to a parameter on your function. Ex:

$.(".fooClass").each(curryThis((node) => {

//some useful code using node


Is there some type of keyword that would get you the unmasked "this" in the callback function? The only alternative I could find to manually doing the closure myself was to use a currying function that would put "this" as the first parameter to my arrow function.