Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #14251
| From | Holger Suhr <holgerholgerde@yahoo.de> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: function(){}() and subsequent calls |
| Date | 2012-05-31 08:51 +0200 |
| Message-ID | <jq74ed$s3p$1@news01.versatel.de> (permalink) |
| References | <z42dnVxvhJ19m1rSnZ2dnUVZ_vCdnZ2d@westnet.com.au> |
Am 31.05.2012 07:51, schrieb Andrew Poulos:
> With
> var foo = function() {}()
> if I later call
> foo()
> I get an error. Whereas using
> var foo = function() {}
> lets me call
> foo()
>
> Adding the succeeding parentheses calls the function but does it alter
> it as well?
>
> Andrew Poulos
var foo = function(){}();
executes the no-name function and assingns the return value to foo.
typeof foo == "undefined"
var foo = function(){return true;}();
typeof foo == "boolean"
var foo = function(){};
assigns the function to foo
typeof foo == "function"
var foo = function(){return true;};
typeof foo == "function"
Holger
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
function(){}() and subsequent calls Andrew Poulos <ap_prog@hotmail.com> - 2012-05-31 15:51 +1000
Re: function(){}() and subsequent calls Holger Suhr <holgerholgerde@yahoo.de> - 2012-05-31 08:51 +0200
Re: function(){}() and subsequent calls Andrew Poulos <ap_prog@hotmail.com> - 2012-05-31 17:12 +1000
Re: function(){}() and subsequent calls Gregor Kofler <usenet@gregorkofler.com> - 2012-05-31 13:40 +0200
Re: function(){}() and subsequent calls Matt McDonald <matt@fortybelow.ca> - 2012-05-31 09:57 -0600
Re: function(){}() and subsequent calls Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-06-01 01:12 +0200
csiph-web