Chapter 5. The Good Parts

JavaScript is a tricky beast, and knowing the parts that you should avoid is just as important as knowing about the parts you should use. As Sun Tzu says, “know your enemy,” and that’s exactly what we’re going to do in the chapter, exploring the dark side of JavaScript and revealing some of the lurking monsters ready to pounce on the unsuspecting developer.

As I mentioned in the Preface, CoffeeScript’s awesomeness lies not only in its syntax, but in its ability to fix some of JavaScript’s warts. However, the language is not a silver bullet to all of JavaScript’s bugbears, and there are still some issues you need to be aware of.

The Unfixed parts

While CoffeeScript goes some length to solving some of JavaScript’s design flaws, it can only go so far. As I mentioned previously, CoffeeScript is strictly limited to static analysis by design, and doesn’t do any runtime checking for performance reasons. CoffeeScript uses a straight source-to-source compiler, the idea being that every CoffeeScript statement results in an equivalent JavaScript statement. CoffeeScript doesn’t provide an abstraction over any of JavaScript’s keywords, such as typeof, and as such, some design flaws in JavaScript’s design also apply to CoffeeScript.

We’re going to first talk about some issues that CoffeeScript can’t fix, and then touch on a few JavaScript design flaws that CoffeeScript does fix.

Using eval

While CoffeeScript removes some of JavaScript’s foibles, ...

Get The Little Book on CoffeeScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.