jslint

JSLint says “missing radix parameter”

我与影子孤独终老i 提交于 2019-11-26 11:47:03
问题 I ran JSLint on this JavaScript code and it said: Problem at line 32 character 30: Missing radix parameter. This is the code in question: imageIndex = parseInt(id.substring(id.length - 1))-1; What is wrong here? 回答1: It always a good practice to pass radix with parseInt - parseInt(string, radix) For decimal - parseInt(id.substring(id.length - 1), 10) If the radix parameter is omitted, JavaScript assumes the following: If the string begins with "0x", the radix is 16 (hexadecimal) If the string

(…()) vs. (…)() in javascript closures [duplicate]

那年仲夏 提交于 2019-11-26 11:14:39
This question already has an answer here: Location of parenthesis for auto-executing anonymous JavaScript functions? 4 answers I know this is silly, but there's any difference between this: (function() { var foo = 'bar'; })(); and this? (function() { var foo = 'bar'; }()); JSLint tells us to Move the invocation into the parens that contain the function , but I see no need to. Edit: The answers are too cool. ~function , the JSHint alternative along with jQuery's preference for (/***/)(); and Crockford's explanation! I thought I was going to just get a "they're the same thing" kind of answer.

JSLint error: Move all 'var' declarations to the top of the function

帅比萌擦擦* 提交于 2019-11-26 11:04:54
问题 JSLint site updated, and I cannot check JS scripts anymore. For me, this warning is not critical, and I don\'t want to go through thousands of lines to fix this, I want to find more critical problems. Does anybody know how to turn off this error, or use legacy JSLint? UPDATE Example: function doSomethingWithNodes(nodes){ this.doSomething(); for (var i = 0; i < nodes.length; ++i){ this.doSomethingElse(nodes[i]); } doSomething(); // want to find this problem } jslint.com output: Error: Problem

Why should you not use Number as a constructor? [duplicate]

谁都会走 提交于 2019-11-26 11:02:06
问题 This question already has answers here : Why to avoid creating objects in JavaScript? (2 answers) Closed 2 years ago . I entered this statement in JSLint: var number = new Number(3); And received the following message: Do not use Number as a constructor. Why is that? The statement is creating a number object, not a primitive value, so I don\'t see why using new is a problem. EDIT: Thanks for all the responses. They\'ve got me thinking further, so I posted a follow-up question here. 回答1: In

Why is JSHINT complaining that this is a strict violation?

孤街浪徒 提交于 2019-11-26 10:49:09
问题 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

Don&#39;t make functions within a loop [duplicate]

余生长醉 提交于 2019-11-26 10:39:04
问题 This question already has answers here : How to fix jslint error 'Don't make functions within a loop.'? (6 answers) Closed 3 years ago . 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,

JSlint: unexpected &#39;for&#39; [duplicate]

丶灬走出姿态 提交于 2019-11-26 07:41:15
问题 This question already has an answer here: What does JSLint mean by 'Unexpected expression 'i' in statement position.'? 2 answers I have been testing with radio buttons. Everything seems okay until i ran it through JS lint. I fixed all errors except one: Unexpected \'for\' for (i = 0; i < radios.length; i += 1) { Here is my Javascript: /*global body,window,document,alert*/ (function () { \"use strict\"; var UIlogic; UIlogic = { myLoad: function () { var elems, elemText, btn1, winter, summer,

JSlint error &#39;Don&#39;t make functions within a loop.&#39; leads to question about Javascript itself

╄→尐↘猪︶ㄣ 提交于 2019-11-26 06:39:28
问题 I have some code that invokes anonymous functions within a loop, something like this pseudo example: for (i = 0; i < numCards; i = i + 1) { card = $(\'<div>\').bind(\'isPopulated\', function (ev) { var card = $(ev.currentTarget); .... JSLint reports the error \'Don\'t make functions within a loop.\' I like to keep my code JSLint clean. I know I can move the anonymous function out of the loop and invoke it as a named function. That aside, here\'s my question: Would a Javascript interpreter

What is array literal notation in javascript and when should you use it?

纵然是瞬间 提交于 2019-11-26 06:34:14
问题 JSLint is giving me this error: Problem at line 11 character 33: Use the array literal notation []. var myArray = new Array(); What is array literal notation and why does it want me to use it instead? It shows here that new Array(); should work fine... is there something I\'m missing? 回答1: array literal notation is where you define a new array using just empty brackets. In your example: var myArray = []; It is the "new" way of defining arrays, and I suppose it is shorter/cleaner. The examples

Should I use JSLint or JSHint JavaScript validation? [closed]

末鹿安然 提交于 2019-11-26 06:10:05
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 4 months ago . I am currently validating my JavaScript against JSLint and making progress on, it\'s assisting me to write better JavaScript - in particular in working with the Jquery library. I have now come across JSHint , a fork of JSLint . So I am wondering for web applications, which