O'Reilly logo

Smashing CoffeeScript by Alex Hudson

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 6

Using JavaScript Libraries

When developers move to a new language or to a newer version of one they were already using, they usually have to throw away much, if not all, of the code they had previously written. This can be because the syntax is too different or because its libraries use different APIs, and it’s not always practical to attempt to convert code from the old style to the new. With CoffeeScript, though, things work differently: It compiles into JavaScript.

For the developer already using JavaScript, the move to CoffeeScript is much easier, because none of those problems exist. Old code is still usable, so all of the investment in JavaScript is not lost. It’s better than backward compatibility, though—CoffeeScript is also forward compatible! New code can be written in CoffeeScript and integrated into existing JavaScript projects. This chapter shows you how.

Out of necessity, you will find numerous Java­Script examples—don’t let those put you off! You do need to examine some of the dustier corners. However, by the end of the chapter, you will have explored some of the deeper aspects of JavaScript and should have a renewed appreciation for the work the CoffeeScript compiler is doing for you.

Easy calling conventions: don’t throw away that existing code!

Why would a developer mix CoffeeScript and JavaScript code? This is an important question. And the honest answer, from my perspective, is that in general doing so isn’t a good idea. Also, developing a project ...

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