【发布时间】:2016-07-11 09:22:01
【问题描述】:
我尝试对我的流星应用脚本使用严格模式。但是使用这段代码:
"use strict";
example = function(param) {
var userId = Meteor.userId();
}
给了我两个 linter 错误:
'Meteor' is not defined.
'example' is not defined.
对于最后一个,我认为我必须将函数定义为
const example = function() {}
更新:
然后 linter 给了我错误example is defined, but never used。我在一个单独的文件中定义了一些函数,所以这个函数不会在这个文件中使用。
同样的问题:
var month = parseInt(moment().format('MM'));
moment() 没有定义...
【问题讨论】:
-
window.Meteor = Meteor怎么样?然后将严格模式限制在函数范围内? -
但这会导致代码很糟糕,不是吗?
-
在我的项目中,我使用上述方法,即“使用严格”来发挥作用域。否则我将无法使用任何库。
-
将流星定义为 linter 的全局变量。
-
这似乎让一些 Meteor 用户感到沮丧。见this github issues conversation in which a few workarounds and solutions are discussed。
标签: javascript meteor strict