JSLint says new keyword is missing [duplicate]

久未见 提交于 2019-12-13 12:28:12

问题


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

function A() {

  var MyVar, SomeParameter;

  // do work

  MyVar = FunctionB(SomeParameter);

}

JsLint says I'm Missing 'new'. at the line MyVar = FunctionB(SomeParameter);

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


回答1:


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

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.




回答2:


JSLint thinks the function is a constructor since it's uppercase. Name your non-constructor functions with an initial lowercase letter and JSLint will stop complaining.



来源:https://stackoverflow.com/questions/9650392/jslint-says-new-keyword-is-missing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!