Reputation: 619
I am under the impression that coffeescript translates its code to pure, normal javascript. However, some parts (such as ID selectors), translates in to jQuery ID selectors. This means that I have to link a jQuery script to run this code.
What is the reasoning behind this? Why translate to #
(jQuery) ID selector instead of document.getElementByID
(normal javascript)?
Upvotes: 1
Views: 88
Reputation: 31
jQuery is a library written in JavaScript, not a language.
We just use this library with normal JavaScript, and it has nothing to do with Coffeescript.
Upvotes: 0
Reputation: 239311
You're mistaken. ID selectors aren't a part of CoffeeScript syntax, they're a part of jQuery. When you use $('#whatever')
in CoffeeScript, you're writing jQuery, not CoffeeScript. CoffeeScript isn't "compiling to jQuery", it's already jQuery.
Additionally, document.getElementById
isn't "normal JavaScript". JavaScript is a language, like CoffeeScript is a language. DOM access is an API made available to JavaScript by a browser. Server-side JavaScript, which is every bit as much "normal JavaScript" as in-browser JavaScript, has no such thing as document
.
Upvotes: 3