Answer the question
In order to leave comments, you need to log in
Ways to improve JS code?
Reading this article: habrahabr.ru/post/235943 came across
The template starts with the !function($) { … }($) module, which puts the global jQuery variable in local scope - this will help reduce overhead and prevent conflicts with other libraries.
Answer the question
In order to leave comments, you need to log in
Signs ! , - , + make the interpreter evaluate (in this case, execute) what is on the right. For example, Bootstrap has a + sign inserted everywhere for this.
However, it would be more correct to rewrite the code like this:
(function ($){
"use strict";
}(this.jQuery));
(function (W, D){
// W = window (1 символ против 6)
// D = document (1 символ против 8)
"use strict";
}(window, document));
Maxim Dunayevsky with brackets is not more correct, but a little more readable.
If we talk about correctness, then with respect to void void function(i) {console.log(i)}(10);
Variables in closures in terms of debugging are even worse than global variables, and local ones are really faster than both.
Now it’s worth focusing not on the five-year-old ES3 tricks, but on modern tools like browserify / webpack with bebel and debug beautiful ES2015 / ES2016 in the browser using sourcemaps.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question