为什么JSLint对此功能发出严重的违规错误? [英] Why does JSLint give strict violation error on this function?

查看:132
本文介绍了为什么JSLint对此功能发出严重的违规错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JSLint给了我严重违规错误,尽管我在一个隐藏在全局范围内的函数中使用了this上下文。

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";
}

为了记录,我在Webstorm中使用内置的JSLint解析器。 / p>

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

推荐答案

这是因为JSLint不会将您的函数识别为构造函数。按惯例,您必须使用大写字母。

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";
}

这篇关于为什么JSLint对此功能发出严重的违规错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆