jslint

Function declaration in CoffeeScript

ε祈祈猫儿з 提交于 2019-11-27 18:26:31
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 declaration, as long as the function is declared at the top of the scope. CoffeeScript uses function

How do I safely “eval” user code in a webpage?

两盒软妹~` 提交于 2019-11-27 18:08:25
问题 I'm working on a webapp to teach programming concepts. Webpages have some text about a programming concept, then let the user type in javascript code into a text editor window to try to answer a programming problem. When the user clicks "submit", I analyse the text they've typed to see if they have solved the problem. For example, I ask them to "write a function named f that adds three to its argument". Here's what I'm doing to analyse the user's text: Run JSLint on the text with strict

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

本小妞迷上赌 提交于 2019-11-27 18:04:34
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); 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 the result of the function call in a parens ... 来源: https://stackoverflow.com/questions/4979252/jslint

jsLint error: “somefunction() was used before it was defined”

我是研究僧i 提交于 2019-11-27 17:15:49
问题 Why does JSLint complain if something uses a function that hasn't been defined already? The point is that the function is defined -- and if that something calls that function, that function exists and things will work. Take a look at the code below: function foo() { // calls bar() }; function bar() { // calls foo() }; There is no way to organize the 2 methods in such a way that it would make JSLint happy. How do I deal with this issue? 回答1: See this answer: Contending with JS "used before

What does the JSLint error 'body of a for in should be wrapped in an if statement' mean?

▼魔方 西西 提交于 2019-11-27 16:35:00
I used JSLint on a JavaScript file of mine. It threw the error: for( ind in evtListeners ) { Problem at line 41 character 9: The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype. What does this mean? vava First of all, never use a for in loop to enumerate over an array. Never. Use good old for(var i = 0; i<arr.length; i++) . The reason behind this is the following: each object in JavaScript has a special field called prototype . Everything you add to that field is going to be accessible on every object of that type. Suppose you want all

JSLint (CLI): options?

只愿长相守 提交于 2019-11-27 14:46:50
问题 I'm running JSLint's Rhino version from the Ubuntu command line like so: $ rhino jslint.js myScript.js While the web interface offers various options, I couldn't figure out how to invoke those via the command line. Am I overlooking anything in the documentation? 回答1: Yes! You did miss it. You can specify the options for jslint at the top of your .js file. See the doc page and read the options section for an example. 回答2: I was inspired by the discussion above, and extended my JSLint wrapper

JSLint - ignore sections of code

柔情痞子 提交于 2019-11-27 14:22:27
问题 I have a huge script that passes JSLint (including avoidance of all bad parts). Except for one stretch, which is some very convoluted obfuscated code that is embedded within the larger context. JSLint generates quite a bit of complaints for this section, and I'd like to selectively disable it for that stretch of code. I already do use selective /*jlsint xxx:true/false*/ directives to disable particular warnings for certain tiny stretches of code that do things contrary to the struct

Jquery and Jslint - '$' was used before it was defined

旧城冷巷雨未停 提交于 2019-11-27 12:37:05
I have some third party javascript im working with, I added some jquery code into it the javascript file. But it seems to fail on the above code when validating using Jslint '$' was used before it was defined. I can see at the top of the javascript file it states: /*global alert: false, console: false, jQuery: false */ Im relatively new to Javascript, and JQuery, so any help would be welcome. kernel Add these options to your comments: /*jslint browser: true*/ /*global $, jQuery, alert*/ If you want to use variables provided by other scripts, then you need to say so: /*global $ */ For JSLint In

JSLint Error: Unexpected 'this'

孤街醉人 提交于 2019-11-27 12:35:19
Having trouble understanding why JSLint is surprised by my use of this in the following code: function testConstr (x) { 'use strict'; this.joker = "Whyyy sooo seriousss?"; this.x = x; } For both property assignments, JSLint says: Unexpected 'this'. How do I correct my code? Your code might be perfectly correct (it might also be problematic, depending on how you call testConstr ). My suggestion is: tell JSLint to shut up Or don't use JSLint at all. ruffin So in other words, JSLint doesn't automatically expect me to use a constructor pattern? You know, I think you're right. Your question bugged

JSLint reports “Unexpected dangling” character in an underscore prefixed variable name

谁说胖子不能爱 提交于 2019-11-27 11:37:47
I know that some people consider the presence of a leading underscore to imply that a variable is "private," that such privacy is a fiction, and assume this is why JSLint reports such names with an error message. I use Google Analytics on a Web site I am building. I make reference to GA's variables, such as "_gaq." I am trying to get my JS code to be 100% JSLint clean (I'm not religious about my coding style, and so will go with Mr. Crockford's counsel). That said, I can't do anything about Google's variables names... so, I guess I can't get 100% "clean." I post here in case I've misunderstood