Reputation: 1534
I come to this question:
f = (param) ->
console.info '#{param}'
f(1)
The outcome is #{param}
When I enclose the string with double quotation marks, this just print 1
. I have also tested it in Ruby, its behaviour is the same. But that just contradicts the rule in CoffeeScript.org:
The golden rule of CoffeeScript is: "It's just JavaScript".
Because I think in Javascript, single quotes and double quotes are treated equally. And I do not use Ruby often. Can anyone explain why?
Thanks a lot.
Upvotes: 8
Views: 4433
Reputation: 146084
"It's just javascript" means it fundamentally compiles to ordinary JavaScript and doesn't attempt to take a radically different programming paradigm and compile it to JavaScript. CoffeeScript is primarily concerned with avoiding "the bad parts", boilerplate, and unnecessary syntax as opposed to introducing radically different basic constructs such as data types, etc.
JavaScript has no string interpolation. CoffeeScript brings this over from Ruby as a convenience. Disabling it for single quotes just gives you a clean way to get a string without the interpolation interpreted.
Don't take It's just JavaScript to mean It IS JavaScript. It's a flavor/variant/sibling.
Upvotes: 11
Reputation: 245449
From the CoffeeScript documentation:
Ruby-style string interpolation is included in CoffeeScript. Double-quoted strings allow for interpolated values, using #{ ... }, and single-quoted strings are literal.
Upvotes: 15