Javascript! Function () {}

looking at the Sizzle mini-code, I noticed that it starts as follows:

!function(a){//...

  }(window)

Why is there an exclamation mark in the beginning?

I thought I !was a cameraman not.

Thanks.

Edit:

Full code .

+4
source share
2 answers
!function(a){/* ... */}();

Using a unary operator to invoke IIFE is common practice. This is a generic shortened version for:

(function(a){/* ... */}());

or

(function(a){/* ... */})();

You can also replace a non-unary operator with any other unary operator:

-function(a){ /* ... */ }();
+function(a){ /* ... */ }();
/* ... etc. */
+6
source

gives a good explanation for calling the function https://github.com/airbnb/javascript/issues/44#issuecomment-13063933

!function () {}();

equivalently

(function(){})();

1 .

.

!function aaa(){}()
!function bbb(){}();

:

!function aaa(){}()
;(function bbb(){})();

";" . , js, .

, :

, . ?!

: ?

+4

Source: https://habr.com/ru/post/1525351/


All Articles