Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #28998

Re: What Does This Code Do?

From Joao Rodrigues <groups_jr-1@yahoo.com.br>
Newsgroups comp.lang.javascript
Subject Re: What Does This Code Do?
Date 2015-12-09 18:17 -0200
Organization Aioe.org NNTP Server
Message-ID <n4a28o$75t$3@speranza.aioe.org> (permalink)
References <62tg6b5gdt3v9fprpj1runb86d7lsr1f7b@4ax.com>

Show all headers | View raw


Em 09/12/2015 16:44, Gene Wirchenko escreveu:
>
>       I am stuck at the start.  What does "!function" mean?
>

"!function" is another form of writing an Immediately-Invoked Function 
Expression (IIFE) in ES5:

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

Or

(function() {
   /* etc. */
}()); // Douglas Crockford's preference.

We can also use unary operators instead of the wrapping parentheses,
if we don't care about the return value of the IIFE:

+function() { /*...*/ }();
!function() { /*...*/ }();
-function() { /*...*/ }();
~function() { /*...*/ }();

Even the void operator can be used:
void function () { /*...*/ }();

The whole point of using parens or an operator is to enforce an
expression context.


In ES2015 (aka ES6), we can replace IIFE with a block and a let declaration:
     {  // open block
         let tmp = ···;
         ···
     }  // close block

or with a module [2].

[2] <http://exploringjs.com/es6/ch_callables.html#sec_iifes-in-es6>


> I suspect that this code was run through a compresser of some sort.
> ("3e3" to save a byte over "3000" and the like.) I can understand
> bits of it, but I can not parse it in total.
>
> *** Start of Code ***
 > !function(a,b,c){function d(a){var ... (snip)


There are some dev tools called "beautifiers" to make the code more 
readable, such as http://jsbeautifier.org/ or 
http://codebeautify.org/jsviewer. Also you can try the Sublime-text 
editor with a package to do so (jsBeautifier, jsFormat, etc.)


-- 
Joao Rodrigues

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

What Does This Code Do? Gene Wirchenko <genew@telus.net> - 2015-12-09 10:44 -0800
  Re: What Does This Code Do? Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2015-12-09 18:17 -0200
  Re: What Does This Code Do? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-12-10 00:31 +0100

csiph-web