Javascript 从函数导出变量
我在coffeescript文件中有一个类:Javascript 从函数导出变量,javascript,coffeescript,Javascript,Coffeescript,我在coffeescript文件中有一个类: class Grid constructor: (size) -> @size = size @algo = new Algo() @cells = @empty() 它生成JS文件: (function() { var Grid; Grid = (function() { function Grid(size) { this.size = size; this.algo
class Grid
constructor: (size) ->
@size = size
@algo = new Algo()
@cells = @empty()
它生成JS文件:
(function() {
var Grid;
Grid = (function() {
function Grid(size) {
this.size = size;
this.algo = new Algo();
this.cells = this.empty();
}
// ...
}).call(this);
我有另一个JS文件,在我的第一个JS文件之后,我已经将它包含到HTML中。在这个JS文件中,我想创建一个Grid类的实例,但是Grid类不在全局范围内,所以我不能这样做:
grid = new Grid(4);
如何在另一个JS文件中使用Grid类?使用
class@Grid
这应该会将编译的代码更改为使用this.Grid=(function(){…
其中this
将是窗口