jslint

Function declarations should not be placed in blocks. Use a function expression or move the statement to the top of the outer function

怎甘沉沦 提交于 2019-11-27 03:51:05
问题 I have the following code: if (typeof console === "object" && typeof console.error === "function") { function e(msg) {"use strict"; console.info(msg);} } For which jsLint gives the following error: Function statements should not be placed in blocks. Use a function expression or move the statement to the top of the outer function. Why is it giving this error and what does it mean? 回答1: You should not be creating function inside if block. You are much better off doing: var e = function(){}; if

Why is JSHINT complaining that this is a strict violation?

旧城冷巷雨未停 提交于 2019-11-27 03:47:47
I think this may be a duplicate of Strict Violation using this keyword and revealing module pattern I have this code: function gotoPage(s){ if(s<=this.d&&s>0){this.g=s; this.page((s-1)*this.p.size);} } function pageChange(event, sorter) { var dd = event.currentTarget; gotoPage.call(sorter, dd[dd.selectedIndex].value); } And JSHINT (JSLINT) is complaining. It says "Strict violation." for the highlighted line: Is my use of Function.call() and then referencing the instance, somehow inappropriate? Is this considered to be bad style? JSHint says "Possible strict violation" because you are using

Don't make functions within a loop [duplicate]

ε祈祈猫儿з 提交于 2019-11-27 03:35:39
This question already has an answer here: How to fix jslint error 'Don't make functions within a loop.'? 6 answers What would be the correct way to solve the jslint error in this case? I'm adding a getter function to an object which uses this. I don't know how to do this without creating the function inside the loop. for (var i = 0; i<processorList.length; ++i) { result[i] = { processor_: timestampsToDateTime(processorList[i]), name_: processorList[i].processorName, getLabel: function() { // TODO solve function in loop. return this.name_; } }; } Rob W Move the function outside the loop:

How to fix “foo is not defined” error reported by JSlint? [duplicate]

自作多情 提交于 2019-11-27 02:01:46
问题 Possible Duplicate: JSLint: was used before it was defined I run JSlint and saw errors like that: 'foo' is not defined. var x = foo(); foo is a function defined in another JavaScript file foo.js . As I understand there is no "import / require" directives in JavaScript to reference the foo function defined in another source file. How can I fix this error repoted by JSlint ? 回答1: Use the global directive to tell JSLint about foo 's assumed existence. /*global foo */ http://www.jslint.com/help

JSLint “insecure ^” in regular expression

倾然丶 夕夏残阳落幕 提交于 2019-11-27 01:56:55
JSLint reports Insecure '^' for the following line. Why is that? Or is it just going to complain any time I want to negate a character class? // remove all non alphanumeric, comma and dash characters "!$7s-gd,&j5d-a#".replace(/[^\w,\-]/g, ''); It only will do this if you have the option selected at the bottom: Disallow insecure . and [^...] in /RegExp/ From the docs : true if . and [^...] should not be allowed in RegExp literals. These forms should not be used when validating in secure applications. So the answer your question, if you start a regex with ^ and it's checked, yes it'll throw the

Prevent JSHint warning that 'functionName is defined but never used'

倖福魔咒の 提交于 2019-11-27 01:00:34
问题 I have just started using JSHint (through the Sublime-Linter package for Sublime Text 2). I would like to suppress its warnings regarding functions that are used before they are defined, as I see no problem with using function definitions like this. For example, the following code generates warnings: (function($){ $(document).ready(function() { formValidationSetup(); refreshErrorMessages(); }); function formValidationSetup() { } function refreshErrorMessages() { } })(jQuery); The warnings:

Is there a working JSLint Eclipse plug-in?

筅森魡賤 提交于 2019-11-27 00:03:00
问题 Can anyone point to a functioning JSLint plug-in for Eclipse? 回答1: There is a plugin here and it works ok. (site is down sometime in 2011) The update site is http://update.rockstarapps.com/site.xml (site down 2012-07-24) You can also run jslint4java as an external tool: Download jslint4java Put jslint4java.jar somewhere Add an external tool configuration in Eclipse (Run > External Tools > External Tools Configurations > Program > New...): Location: /usr/bin/java (or your path to javaw.exe)

The “unexpected ++” error in jslint [duplicate]

醉酒当歌 提交于 2019-11-26 23:57:09
问题 This question already has an answer here: Why avoid increment (“++”) and decrement (“--”) operators in JavaScript? 17 answers What is the best practice for that then? Jslint explains that it "adds confusion". I don't see it really... EDIT: The code, as requested: var all,l,elements,e; all = inElement.getElementsByTagName('*'); l = all.length; elements = []; for (e = 0; e < l; (e++)) { if (findIn) { if (all[e].className.indexOf(className) > 0) { elements[elements.length] = all[e]; } } else {

Function declaration in CoffeeScript

蓝咒 提交于 2019-11-26 19:26:59
问题 I notice that in CoffeeScript, if I define a function using: a = (c) -> c=1 I can only get the function expression : var a; a = function(c) { return c = 1; }; But, personally I often use function declaration ,for example: function a(c) { return c = 1; } I do use the first form, but I'm wondering if there is a way in CoffeeScript generating a function declaration. If there is no such way, I would like to know why CoffeeScript avoid doing this. I don't think JSLint would holler an error for

JSLint error: “Move the invocation into the parens that contain the function”

烈酒焚心 提交于 2019-11-26 19:16:43
问题 What does JSLint mean by this error? And how should it be rewritten? Error: Problem at line 78 character 3: Move the invocation into the parens that contain the function: })(jQuery); 回答1: To pass JSLint's criteria, it needs to be written like this: }(jQuery)); Though I think that particular criteria is a bit subjective. Both ways seem fine in my opinion. (function () {})() makes a bit more sense to me since you wrap the full function, then call it (function () {}()) looks like you're wrapping