Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #22265
| Message-ID | <3978495.o0mb1hJGK2@PointedEars.de> (permalink) |
|---|---|
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Organization | PointedEars Software (PES) |
| Date | 2013-12-09 00:15 +0100 |
| Subject | Re: Anonymous self-invoking function |
| Newsgroups | comp.lang.javascript |
| References | <RP-dneojCe_X4T_PnZ2dnUVZ5sWdnZ2d@giganews.com> <1a85f00c-d0b2-4e77-b7b5-37a2bd628dc5@googlegroups.com> |
jaranmclarn@gmail.com wrote:
^^^^^^^^^^^^^^^^^^^^^
Who?
> LOREMN
I beg your pardon?
> 1) As Thomas 'PointedEars' Lahn stated (paraphrased in so many words
> Resig is being lazy) This is the code that is valid in ECMAScript 5
> using 'use strict';
>
>
> (function() {
> 'use strict';
It is not necessary to wrap the strict mode declaration in another function.
It suffices that the script resource begins with the declaration. (The
Chromium script console has a known quirk there, though.)
> /* Anonymous self-invoking function */
> (function() {
> this.assert = function assert(a,b) { /* code here */ };
> this.test = function test(a, b) { /* code here */ };
> }).call({}, this);
This would make (a reference to) a new Object instance the “this” value in
the function when it is called. The function would also be passed the
global object as only argument which, since there is no formal parameter
declared for it, would only be accessible using the “arguments” object.
> /* Code for a testing environment or "test groups" */
> window.onload = function() {
> window.test("Test one.", function() {
> window.assert(true, "Success!");
> });
> };
>
> })(); /* Note this outer anonymous self-invoking function is
> only there so I can shoehorn in the 'use strict'; JSHint.com
> moans if it is not there */
JSHint.com is junk then.
> I don't know what's going on with the first two examples in [Thomas's]
> code...(I just got an error and I think he's forgotten that with CALL()
There is no “CALL”, the method name is “call” (case-sensitive).
> the first argument;s job is to be the object refenced by 'this' when the
> function invoked by call is run;
You have forgotten that as well above. I have corrected myself twice before
you posted your “correction”.
> the second and subsequent arrguments become the arguments passed into said
> function.
That is correct. Which is why your code above is not equivalent.
> So if in the function CALL
> is invoked upon has the parameter signature function(global) ... then the
> 2nd parameter (from my example 'this' i.e. 'call({}, this)' becomes mapped
> to the named local scope var called 'global' when this function
> executes...I've put in the '{}' as a placeholder.
To what end? You are not returning the reference to the newly created
object, nor are you declaring a formal parameter or are accessing the global
object in any other way.
> […]
Please either learn to post using Google Groups in a readable manner and
*in thread*, or use a newsreader like KNode, SeaMonkey or Thunderbird. The
latter is strongly recommended anyway because Google Groups is continuing to
be buggy (i.e., ignoring both Internet standards and Usenet recommendations)
and a source of spam.
--
PointedEars
Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Find similar | Unroll 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