在严格模式下定义变量

Defining variable in strict mode

我尝试对我的 meteor-app 脚本使用严格模式。但是使用这个代码:

  "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() 未定义...

linter 不知道 Meteormoment 因为它们是由其他脚本定义的。

如何处理取决于您使用的 linter。

/* global Meteor, moment */ 放在脚本顶部可能会解决问题。