最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Why does JSLint give strict violation error on this function? - Stack Overflow

programmeradmin7浏览0评论

JSLint gives me the "strict violation" error, although I use the "this" context inside a function which hides it from the global scope.

function test() {
    "use strict";
    this.a = "b";
}

For the record, I use the built-in JSLint parser in Webstorm.

JSLint gives me the "strict violation" error, although I use the "this" context inside a function which hides it from the global scope.

function test() {
    "use strict";
    this.a = "b";
}

For the record, I use the built-in JSLint parser in Webstorm.

Share Improve this question edited Jul 22, 2013 at 9:49 Erik Bergstedt asked Jul 21, 2013 at 7:28 Erik BergstedtErik Bergstedt 91210 silver badges27 bronze badges 3
  • When I paste this code into JSLint., all default options, I do not receive an error. What was the context of the error where changing the function name removed it? – ruffin Commented Jul 22, 2013 at 3:45
  • I'm using Webstorm which maybe has an outdated version of JSLint – Erik Bergstedt Commented Jul 22, 2013 at 9:33
  • Any chance you have two functions named (the equivalent of) test (in your live code)? Then changing case would make them different. – ruffin Commented Jul 22, 2013 at 16:12
Add a ment  | 

1 Answer 1

Reset to default 10

This is because JSLint doesn't recognize your function as a constructor. By convention, you must use uppercase letters.

function Test() {
    "use strict";
    this.a = "b";
}
发布评论

评论列表(0)

  1. 暂无评论