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


Groups > comp.lang.javascript > #22253

Re: Anonymous self-invoking function

Message-ID <5905423.NgFD1iC58s@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Organization PointedEars Software (PES)
Date 2013-12-08 01:08 +0100
Subject Re: Anonymous self-invoking function
Newsgroups comp.lang.javascript
References <RP-dneojCe_X4T_PnZ2dnUVZ5sWdnZ2d@giganews.com> <m28uvxcqyd.fsf@nntp.bednarz.nl> <T_ydnZ1AqOvn6j7PnZ2dnUVZ5oOdnZ2d@giganews.com> <1963861.2MBlU7BgDz@PointedEars.de>

Show all headers | View raw


Thomas 'PointedEars' Lahn wrote:

> […]
> 
> The proper way is either to explicitly call the function with a reference
> to the global object as the “this” value, or read “this” in global context
> into a variable and use that variable (and to avoid window.onload):
> 
>   (function (global) {
>     global.assert = function () { … };
>   }).call(this);
> 
> or
> 
>   (function (global) {
>     global.assert = function () { … };
>   }).call(null);

JFTR:

  (function (global) {
    global.assert = function () { … };
  }).call(this);

or

  (function () {
    this.assert = function () { … };
  }).call(null);

or

  (function (global) {
    this.assert = function () { … };
  }).call(void 0);

> or
> 
>   (function (global) {
>     global.assert = function () { … };
>   }(this));
> 
> […]

-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

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


Thread

Anonymous self-invoking function "Robert Crandal" <noreply2me@yahoo.com> - 2013-12-06 18:39 -0700
  Re: Anonymous self-invoking function Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2013-12-07 03:52 +0100
    Re: Anonymous self-invoking function "Robert Crandal" <noreply2me@yahoo.com> - 2013-12-07 12:31 -0700
      Re: Anonymous self-invoking function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-12-08 00:17 +0100
        Re: Anonymous self-invoking function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-12-08 01:08 +0100
          Re: Anonymous self-invoking function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-12-08 19:41 +0100
          Re: Anonymous self-invoking function jaranmclarn@gmail.com - 2013-12-08 12:21 -0800
        Re: Anonymous self-invoking function "Robert Crandal" <noreply2me@yahoo.com> - 2013-12-09 01:14 -0700
          Re: Anonymous self-invoking function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-12-10 15:38 +0100
  Re: Anonymous self-invoking function Bjoern Hoehrmann <bjoern@hoehrmann.de> - 2013-12-07 12:28 +0100
    Re: Anonymous self-invoking function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-12-07 12:57 +0100
  Re: Anonymous self-invoking function Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2013-12-07 16:51 -0200
  Re: Anonymous self-invoking function jaranmclarn@gmail.com - 2013-12-08 12:17 -0800
    Re: Anonymous self-invoking function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-12-09 00:15 +0100

csiph-web