|
|
|
|
|
by d_k_f
879 days ago
|
|
When you didn't know how this worked, CoffeScript's fat arrow functions became a life saver when attaching callbacks from inside some object you were writing that probably had an init() method to set up the handlers: // Doesn't work, <this> is <window>.
document.body.addEventListener("click", function(event) { this.handleClick(event) })
vs. document.body.addEventListener "click", (event) => @handleClick(event)
You only needed a .bind(this) in the plain JS version, but it felt like surprisingly few people knew this back then.Interestingly enough, the current version of CoffeeScript compiles this code into a ES6 arrow function itself, but I think back then they used bind() in the transpiled JS. |
|