在 Coffeescript.org 上:
bawbag = (x, y) ->
z = (x * y)
bawbag(5, 10)
将编译为:
var bawbag;
bawbag = function(x, y) {
var z;
return (z = (x * y));
};
bawbag(5, 10);
在 node.js 下通过 coffee-script 进行编译会这样包装:
(function() {
var bawbag;
bawbag = function(x, y) {
var z;
return (z = (x * y));
};
bawbag(5, 10);
}).call(this);
文档说:
如果您想创建顶级变量供其他脚本使用,请将它们作为属性附加到窗口或 CommonJS 中的导出对象上。如果您同时针对 CommonJS 和浏览器,则存在运算符(如下所述)为您提供了一种可靠的方法来确定将它们添加到何处: root = exports ? 这
然后如何在 CoffeeScript 中定义全局变量。“将它们作为属性附加到窗口”是什么意思?