JSLint说缺少新的关键字 [英] JSLint says new keyword is missing

查看:135
本文介绍了JSLint说缺少新的关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一些看起来像这样的JavaScript:

Let's say I have some JavaScript that looks like this:

function A() {

  var MyVar, SomeParameter;

  // do work

  MyVar = FunctionB(SomeParameter);

}

JsLint说我失踪'新'。在MyVar = FunctionB(SomeParameter)行;

我为什么要重写为 MyVar = new FunctionB(SomeParameter) ; 会有什么好处吗?

Why should I rewrite as MyVar = new FunctionB(SomeParameter); Is there going to be any benefit?

推荐答案

这是约定构造函数(例如: Array Object )以大写字母开头。

It is the convention that constructors (eg: Array, Object) are starting with a capital.

JSLint抱怨,因为它认为你正在尝试使用构造函数,而不是关键字。要解决此问题,请使用非大写字符启动函数。

JSLint complains, because it thinks that you're trying to use a constructor, without new keyword. To fix the problem, start your function with a non-uppercase character.

这篇关于JSLint说缺少新的关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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