从Meteor 0.5.4升级到Meteor 0.6.4.1后,我相应地修改了我的coffeescript代码,以反映变量范围的变化。出于某种原因,我认为这些变化使coffeescript与javascript解释相混淆?
当前代码:
@liveObjects = {}
test = () ->
if liveObjects.intervalID?
donothing;
liveObjects = {} --Maybe this is what caused the confusion? Mistaken as a local variable declaration?
从Chrome工具中我发现javascript代码为
(function() { var test;
this.liveObjects = {};
test = function() {
var liveObjects;
if (liveObjects.intervalID != null) { --ReferenceError: liveObjects is not defined
donothing;
}
liveOjects = {};
答案 0 :(得分:1)
您必须再次使用此/ @设置它。
@liveObjects = {}
test = () ->
if liveObjects.intervalID?
donothing;
@liveObjects = {}