(function(a){ alert(a); }(1)); (function (a) { alert(a); })(1); What is the difference between these functions?
Or from the example of Stefanov:
var result = (function () { return 2 + 2; }()); (function () { alert('watch out!'); })(); (function(a){ alert(a); }(1)); (function (a) { alert(a); })(1); What is the difference between these functions?
Or from the example of Stefanov:
var result = (function () { return 2 + 2; }()); (function () { alert('watch out!'); })(); In general, there is no difference.
Douglas Crockford found the record:
(function () { //body }()); It is correct, and the notation:
(function () { //body })(); Wrong and dismissively calls her "dog eggs" (dog balls).
Therefore, use the one that you like more (for example, I agree with Douglas, although the second option is not at all annoying).
For example, in Perl generally prescribed by the slogan that everything should have several ways of notation.
How is JS worse? :)
}()); easier to type than })(); . - user207618Source: https://ru.stackoverflow.com/questions/567098/
All Articles