Why does Twitter use function syntax in its code for embedding

I watched the inline Twitter code and saw that they use !function . Although I know this is being evaluated as false, I was wondering what was the matter.

Here is the code I have in mind:

 !function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs"); 
+4
source share
1 answer

It will save the byte. This is the shortest way to call a function. An alternative would be the following:

 (function(){...})(); 

Check out the Twitter syntax:

 !function(){...}(params); 

This means that they reduced the length to call the function one byte at a time.

EDIT: Only after a thought: it also clearly shows that you are calling an anonymous function.

+6
source

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


All Articles