3 ms·
Wow, this article actually had the opposite of its intended effect with me. I had always expected that CoffeeScript was a better form of JS that I should proba
by jasonkester 16y ago
Wow, this article actually had the opposite of its intended effect with me. I had always expected that CoffeeScript was a better form of JS that I should probably get around to learning. Now I've just learned that besides having an unpleasant syntax, it actually redefines some important features of javascript to behave in novel ways.
As an example, the whole point of setTimeout is to be able to do the sort of thing shown in Example 4. Defeating it just means you now have to search for another way to do the things that setTimeout was designed for.
Same with variable scope. If you can't declare a global without actually standing in the global scope, that makes things harder, not easier.
Beyond that, I glazed over at seeing various little ascii arrows. I'm sure they're there for a reason, but by then I was already halfway out the door.
- jacobolus 16y agoFirst, use or don’t use what you want. If you don’t like the cleaner CS syntax, stick to writing raw JS. Your other points aren’t especially valid though: 1) You can trivially use setTimeout just as you did before. CoffeeScript just gives you a couple extra tools for simplifying things when you have use cases like the one presented in the article. 2) As for the global namespace: if you want to attach something to the window object it’s much more readable to just write "window.foo = bar" or whatever. In general though, I defy you to come up with an example where you want to define global variables from some other scope where your code wouldn’t end up just as clear but more robust with cross-scope variables defined in some high-level scope. Pretty much everyone agrees that JavaScript’s "pollute the global namespace by default" feature was a mistake. The ascii arrows are by far the best part. JavaScript turns out to be a very nice language (semantically) for writing functional-style code. Unfortunately, the regular JavaScript syntax makes defining functions so unpleasant that I go out of my way to avoid extra ones. CoffeeScript makes defining functions so easy that I go looking for ways to use more, instead.