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

There’s no difference. Both are valid ways to get the JavaScript parser to treat your function as an expression instead of a declaration. Note that + and ! will also work, and are sometimes used by minifiers to save a character of size: +function() { var foo = ‘bar’; }(); !function() { var foo = … Read more

Is it bad practice to use the same variable name in multiple for-loops?

Since variable declarations are hoisted to the top of the scope in which they appear the interpreter will effectively interpret both versions in the same way. For that reason, JSHint and JSLint suggest moving the declarations out of the loop initialiser. The following code… for (var i = 0; i < 10; i++) {} for … Read more

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

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 … Read more

Don’t make functions within a loop [duplicate]

Move the function outside the loop: function dummy() { return this.name_; } // Or: var dummy = function() {return this.name;}; for (var i = 0; i<processorList.length; ++i) { result[i] = { processor_: timestampsToDateTime(processorList[i]), name_: processorList[i].processorName, getLabel: dummy }; } … Or just ignore the message by using the loopfunc option at the top of the … Read more

JSLint’s issue with ‘window’ as a global variable

/*jslint browser: true*/ Was the correct solution to this. As of 2017-07-07, you have to set the global directive manually. From the JSLint documentation: The /*global*/ directive is used to specify a set of globals (usually functions and objects containing functions) that are available to this file. This was commonly used in browsers to link … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)