JSLint 错误:意外的“这个" [英] JSLint Error: Unexpected 'this'

查看:19
本文介绍了JSLint 错误:意外的“这个"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法理解为什么 JSLint 对我在以下代码中使用 this 感到惊讶:

Having trouble understanding why JSLint is surprised by my use of this in the following code:

function testConstr (x) {
    'use strict';
    this.joker = "Whyyy sooo seriousss?";
    this.x = x;
}

对于这两个属性分配,JSLint 说:意外的这个".我该如何更正我的代码?

For both property assignments, JSLint says: Unexpected 'this'. How do I correct my code?

推荐答案

您的代码可能完全正确(也可能有问题,取决于您如何调用 testConstr).

Your code might be perfectly correct (it might also be problematic, depending on how you call testConstr).

我的建议是:告诉JSLint闭嘴

My suggestion is: tell JSLint to shut up

或者根本不使用 JSLint.

Or don't use JSLint at all.

这篇关于JSLint 错误:意外的“这个"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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