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


Groups > comp.lang.javascript > #27547

Re: ! function

Newsgroups comp.lang.javascript
Subject Re: ! function
From "Evertjan." <exxjxw.hannivoort@inter.nl.net>
References <ddSdncub_tOuptbInZ2dnUVZ8gidnZ2d@westnet.com.au>
Date 2015-05-07 13:04 +0200
Message-ID <XnsA49384F0298ADeejj99@194.109.133.246> (permalink)

Show all headers | View raw


Andrew Poulos <ap_prog@hotmail.com> wrote on 07 mei 2015 in 
comp.lang.javascript:

> I was looking at some "swipe" libraries when I happened upon hammer.js.
> <http://hammerjs.github.io/dist/hammer.min.js>
> 
> I've no idea yet as to its quality but the very first line begins with
> 
>! function(a, b, c, d) {
> 
> What's the reason behind starting with an exclamation mark?

!function(a,b,c,d){"use strict";[..

..]}(window,document,"Hammer");

Google is your friend!

The unary operator ! (as do ~, -, +) allows the parameters in the () at the 
end to invoke the function in-place and hides the function name from the 
global, and any other [only outside?] scope/namespace.

<http://stackoverflow.com/questions/3755606/what-does-the-exclamation-mark-
do-before-the-function>

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

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


Thread

! function Andrew Poulos <ap_prog@hotmail.com> - 2015-05-07 20:15 +1000
  Re: ! function "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-07 13:04 +0200
  Re: ! function "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2015-05-07 05:02 -0700
  Re: ! function Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2015-05-07 12:27 -0300
    Re: ! function JJ <jj4public@vfemail.net> - 2015-05-08 00:09 +0700
    Re: ! function "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-07 21:07 +0200
      Re: ! function "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-05-07 21:31 +0200
        Re: ! function "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-07 22:20 +0200
          Re: ! function "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-05-07 23:27 +0200
            Re: ! function "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-05-08 00:26 +0200
              Re: ! function "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-08 11:00 +0200
                Re: ! function James Lewis <lewisje@gmail.com> - 2015-06-05 09:10 -0700
          Re: ! function Scott Sauyet <scott.sauyet@gmail.com> - 2015-05-18 13:31 -0700
            Re: ! function "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-05-19 01:39 +0200
              Re: ! function Scott Sauyet <scott.sauyet@gmail.com> - 2015-05-19 05:48 -0700
        Re: ! function Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2015-05-07 17:47 -0300
          Re: ! function "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-07 23:22 +0200
            Re: ! function Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2015-05-07 19:08 -0300
              Re: ! function "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-08 12:08 +0200

csiph-web