O'Reilly logo

The Little Book on CoffeeScript by Alex MacCaw

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, other features are a necessary ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required