4 ms·
You can write this without any problem: var x = function() { // something } // avoid polluting global scope: !function() { // Some initializat
by Calvein 15y ago
You can write this without any problem:
var x = function() {
// something
}
// avoid polluting global scope:
!function() {
// Some initialization.
}()
- evan_ 15y agoSo now you've gone from a semicolon, which has the sole purpose of separating statements; to a bang, which doesn't make any sense in this context unless you know that it's replacing a semicolon. Better or worse?
- insin 15y agoYou could use anything which separates statements or ensures the function is treated as an expression. Two examples which are more in keeping with the intended use of the operators in question: ;function() { // Some initialization. }() void function() { // Some initialization. }()
- mkopinsky 15y agoSo now we've gone a) from semicolon consistently after statements, to having to remember where to prefix with semicolons, or b) from one character to four. Why aren't we just using the semicolon as it is required in any other (C-based) language?
- mistercow 15y agoJS's syntax is influenced by C via its pretensions of being somehow related to Java, but I think it's a stretch to call it a "C-based language".