O'Reilly logo

CoffeeScript Programming with jQuery, Rails, and Node.js by Michael Erasmus

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

=> and @

In JavaScript, the value of this refers to the owner of the currently executing function, or the object that the function is a method of. Unlike in other object-oriented languages, JavaScript also has the notion that functions are not tightly bound to objects, meaning that the value of this can be changed at will (or accidently). This is a very powerful feature of the language but can also lead to confusion if used incorrectly.

In CoffeeScript, the @ symbol is a shortcut for this. Whenever the compiler sees something like @foo, it will replace it with this.foo.

Although it's still possible to use this in CoffeeScript, it's generally frowned upon and more idiomatic to use @ instead.

In any JavaScript function, the value of this is the object ...

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