jslint

What does JSLint mean by 'Unexpected expression 'i' in statement position.'?

天涯浪子 提交于 2019-11-30 09:24:32
问题 I have a for loop in JavaScript that I have run through JSLint a few times. In the past I received the unexpected++ error , I decided to refactor to make my code more readable. A month or so later JSLint came out with an update and is now showing the warning... Unexpected expression 'i' in statement position. for (i; i < scope.formData.tabs.length; i = i + 1) { //See JSLint.com for why I pulled out i initialization and i = i+1 instead of i++ //and http://stackoverflow.com/questions/3000276

JSLint “document.write can be a form of eval” - How is this so?

放肆的年华 提交于 2019-11-30 09:10:10
I've come across this message in JSLint... document.write can be a form of eval. and was wondering exactly how so? The JSLint instructions page states: The eval function...provide access to the JavaScript compiler. This is sometimes necessary, but in most cases it indicates the presence of extremely bad coding.... So, how does document.write "provide access to the JavaScript compiler" then? Thanks What does your browser do with this? document.write('<script type="text/javascript">window.alert("evaled " + (1 + 2))</script>'); 来源: https://stackoverflow.com/questions/5488843/jslint-document-write

Is there a difference between ++i and i++ in this loop?

你。 提交于 2019-11-30 09:03:47
问题 The array.prototype.reduce function at: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce It has the following loop: for (index = 0; length > index; ++index) { if (this.hasOwnProperty(index)) { if (isValueSet) { value = callback(value, this[index], index, this); } else { value = this[index]; isValueSet = true; } } } I don't think there is a difference whether the index is pre or post incremented here since it's done after the loop iterates each time

JsLint 'out of scope' error

北城余情 提交于 2019-11-30 08:10:44
function test(){ if(true){ var a = 5; } alert(a); } test(); I keep getting 'out of scope' errors in my JS code when I check with JsLint which make no sense to me.So I quickly created an example. Is there something actually wrong with this code piece, as the variable is eventually hoisted to the top of the function anyways. While var localizes a variable to the function and is subject to hoisting, most languages have block scope and not function scope. By using the var keyword inside an if block, but accessing the variable outside that block, you've created a construct that can be confusing to

What is the reason behind JSLint saying there are “too many var statements”

家住魔仙堡 提交于 2019-11-30 06:21:56
问题 JSLint (with the onevar flag turned on) is flagging some javascript code that I have with the following: Problem at line 5 character 15: Too many var statements. I am happy to fix these errors, but I'd like to know, am I doing it for performance or because it is just a bad practice and has a greater potential to introduce bugs in my javascript code. What is the reason behind the onevar flag? I did look at the JSLint docs for the var keyword but it doesn't specifically talk about why multiple

Justifying Crockford claims

一世执手 提交于 2019-11-30 06:11:43
I have read Crockford's JavaScript: The Good Parts and have used his validator JSLint . I am sometimes left wondering the justification behind his recommendations. Below is a list of examples I want substantiated. Why does JSLint signal an error if you don't include "use strict"; ? [See this SO thread .] Why should variable declarations within a function be done using a single var ? [See this SO thread .] Why do we need to put a space between function and () in function () ? Why can't we use continue ? What is wrong with ++ and -- ? Why can't we use the comma operator , (except in the

jslint error: Unexpected 'in'. Compare with undefined, or use the hasOwnProperty

好久不见. 提交于 2019-11-30 06:04:05
问题 I have the following javascript function that fails a jslint check function hasActiveX() { return ('ActiveXObject' in window); } jslint error Unexpected 'in'. Compare with undefined, or use the hasOwnProperty method instead. should I just live with the jslint error, or is there a better way to determine ActiveXObject? I could not find a jslint flag to skip this check? 回答1: I think JSLint is asking you to try: function hasActiveX() { return window.hasOwnProperty('ActiveXObject'); } Or the

Is JSLint available for offline use?

百般思念 提交于 2019-11-30 06:03:18
I'd like to use JSLint , but I am wary of tools that have access to my unfiltered source code. Is there an offline version or is there another similar tool that does " lint error checking" for JavaScript offline? Edit: One with a GUI and that shows you a styled list of errors, instead of a command line interface? If you like the JSLint web interface , you can do File > Save Page As... and Save as type: Web Page, complete (in Firefox, doing it in Internet Explorer may be slightly different) to a local folder. I change the name to jslint.htm to get it under 8.3 with no spaces. It seems to work

Function was used before it was defined - JSLint

末鹿安然 提交于 2019-11-30 01:56:20
问题 JSLint does not like this code saying "'b' was used before it was defined" var a = function () { b(); }, b = function () { alert("Hello, world!"); }; a(); but perfectly happy with this var a, b; a = function () { b(); }; b = function () { alert("Hello, world!"); }; a(); But I am not defining anything in my second code snippet. I am merely declaring variable b. So why is JSLint doing this? Is there a reason I should be declaring all my functions first? PS I understand I could have just changed

jslint: why does this code result in a “Strict violation” error message?

前提是你 提交于 2019-11-30 01:53:41
问题 Running the following simple code results in a "Strict violation." error message. I have been trying to find documentation on why, and how to fix it. Any input will be much appreciated. The error: Error: Problem at line 6 character 4: Strict violation. } (this)); The sample code: /*jslint browser: true, onevar: true, undef: true, nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: true, strict: true, newcap: true, immed: true */ "use strict"; (function (window) { } (this));