by jeroenhd · 2y ago · 0 comments
I suppose you could argue those are just synctatic sugar because they compiled down to ES5, in the same way you can argue that any programming language is synctatic sugar over raw machine code.
I may disagree (_heavily_) with the Pythonesque syntax Coffeescript chose, but it took a while for ES6 to be widely available, and Coffeescript made ES6 features work on most browsers without any additional effort. It's easy to take today's Javascript for granted, but the web was very different back in 2009.
I distinctly remember lots of var that = this; in JS code back then, which wasn't required anymore when using CoffeScript.
javascript is first and foremost functional no matter how hard MS and others have tried to hammer it into a more typical OOP language.
Fixing _this_ is a good point, though.
// 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.