javascript - jshint error : Redefinition of '_' - Stack Overflow

I am using the lodash library in my express application.Whenever I include lodash like:var _ = require

I am using the lodash library in my express application. Whenever I include lodash like:

var _ = require('lodash')

jshint plains with the error:

Redefinition of '_' 

If I remove the require statement, the application fails and reports that it does not recoginice '_'.

My jshint.rc has the following statement:

 "globals": {
    "angular": false,
    "_" : false
  }

But this is so that I can include it in the front-end code without jshint plaining.

How do I ask jshint to ignore this error in my node code ?

I am using the lodash library in my express application. Whenever I include lodash like:

var _ = require('lodash')

jshint plains with the error:

Redefinition of '_' 

If I remove the require statement, the application fails and reports that it does not recoginice '_'.

My jshint.rc has the following statement:

 "globals": {
    "angular": false,
    "_" : false
  }

But this is so that I can include it in the front-end code without jshint plaining.

How do I ask jshint to ignore this error in my node code ?

Share Improve this question edited Aug 4, 2015 at 12:19 runtimeZero asked Aug 4, 2015 at 12:15 runtimeZeroruntimeZero 28.1k28 gold badges79 silver badges130 bronze badges 4
  • in node _ is a reserved word (it's the value from the last instruction evaluated) – Dario Commented Aug 4, 2015 at 12:22
  • Juhana's ment helped resolve. Basically added the following to the top of the file /* jshint -W079 */ – runtimeZero Commented Aug 4, 2015 at 12:23
  • @Juhana I'll trust you, but if I remember well in REPL was that. Am I wrong (just for don't do mistakes one more time)? – Dario Commented Aug 4, 2015 at 12:30
  • 1 @Dario REPLs are allowed to do whatever they like. But just because they assign the last return value to that variable, that doesn’t make it a reserved word. – poke Commented Aug 4, 2015 at 13:54
Add a ment  | 

2 Answers 2

Reset to default 5

You have explicitly told jshint that the global variable _ is read-only.

From the docs:

globals

A directive for telling JSHint about global variables that are defined elsewhere. If value is false (default), JSHint will consider that variable as read-only. Use it together with the undef option.

/* globals MY_LIB: false */

Since you are using require to explicitly define it, I think you can remove _ from the globals list for JSHint to allow assignment to the variable.

If, however, you are using _ without explicitly requiring it and expect it to be present in the environment, then you can set "_" : true in your .jshintrc to still allow assignment to it.

In your jshint.rc you can put: "no-native-reassign" : 0, this will disable the native reassign rule, or you can put /*jshint -W079 */ right before the function where you assign _.

When you don't use _ as a global variable you also should remove it from your Globals in jshint. Or set it to true so jshint doesn't see it as readonly.

sources: JSLint Error explanation

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742358773a4428966.html

相关推荐

  • javascript - jshint error : Redefinition of '_' - Stack Overflow

    I am using the lodash library in my express application.Whenever I include lodash like:var _ = require

    1天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信