As a possible extension for this, is there a way to embed regular JS blocks in CoffeeScript code so that it doesn't compile?
Yes, here is the documentation . You need to wrap the JavaScript code in backticks ( ` ). This is the only way to directly use JavaScript == in CoffeeScript. For example:
CoffeeScript source
[ try ] if `a == b` console.log "#{a} equals #{b}!"
Compiled JavaScript
if (a == b) { console.log("" + a + " equals " + b + "!"); }
Is the specific case == null / undefined / void 0 served by the postfix extension operator ? :
CoffeeScript source
[ try ] x = 10 console.log x?
Compiled JavaScript
var x; x = 10; console.log(x != null);
CoffeeScript Source
[ try ] # `x` is not defined in this script but may have been defined elsewhere. console.log x?
Compiled JavaScript
var x; console.log(typeof x !== "undefined" && x !== null);
Jeremy Banks Aug 11 '11 at 20:33 2011-08-11 20:33
source share