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


Groups > comp.lang.javascript > #7986

Re: calling function within (function() {...})();

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From Gregor Kofler <usenet@gregorkofler.com>
Newsgroups comp.lang.javascript
Subject Re: calling function within (function() {...})();
Date Fri, 04 Nov 2011 14:06:36 +0100
Organization A noiseless patient Spider
Lines 36
Message-ID <j90o0s$vmv$1@dont-email.me> (permalink)
References <j-mdnaRhWZiHRS7TnZ2dnUVZ_uednZ2d@westnet.com.au>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
Injection-Date Fri, 4 Nov 2011 13:06:36 +0000 (UTC)
Injection-Info mx04.eternal-september.org; posting-host="+XM0vj2bkcFvBEYEgl1LEw"; logging-data="32479"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18keE/hYBvdSXvbENteQD+PubYlg5oTCWM="
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20111031 Thunderbird/7.0.1
In-Reply-To <j-mdnaRhWZiHRS7TnZ2dnUVZ_uednZ2d@westnet.com.au>
Cancel-Lock sha1:FnZ9yUtbYQZhWO/VZhoJ9Ci6ev0=
Xref x330-a1.tempe.blueboxinc.net comp.lang.javascript:7986

Show key headers only | View raw


Am 2011-11-04 13:18, Andrew Poulos meinte:
> If I have this
> 
> var x = (function(){
>              return {
>                a : function(){},
>                b : function(){}
>              };
>           })();
> 
> how do I call 'b' from within 'a'? I thought that this
> 
> a : function(){ this.b(); },
> 
> should work but I get "TypeError: 'undefined' is not a function".

Works as expected.

var x = (function(){
  return {
    a : function(){this.b();},
    b : function(){window.alert("hooray!"); console.log(this); }
  };
})();

x.a();

// -> alert dialog
// Object { a=function(), b=function() }

HTH, Gregor


-- 
http://vxweb.net

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


Thread

calling function within (function() {...})(); Andrew Poulos <ap_prog@hotmail.com> - 2011-11-04 23:18 +1100
  Re: calling function within (function() {...})(); Gregor Kofler <usenet@gregorkofler.com> - 2011-11-04 14:06 +0100
    Re: calling function within (function() {...})(); Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2011-11-04 14:13 +0100
      Re: calling function within (function() {...})(); Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-04 15:49 +0100
        Re: calling function within (function() {...})(); Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2011-11-04 16:35 +0100
          Re: calling function within (function() {...})(); Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-04 20:44 +0100
            Re: calling function within (function() {...})(); Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2011-11-04 21:16 +0100
              Re: calling function within (function() {...})(); Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-04 21:24 +0100
                Re: calling function within (function() {...})(); Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-04 21:46 +0100
                Re: calling function within (function() {...})(); Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2011-11-04 23:29 +0100
        Re: calling function within (function() {...})(); Scott Sauyet <scott.sauyet@gmail.com> - 2011-11-04 10:29 -0700
          Re: calling function within (function() {...})(); Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-09 15:17 +0100
            Re: calling function within (function() {...})(); Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2011-11-09 20:13 +0100
              Re: calling function within (function() {...})(); Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-11 23:26 +0100
                Re: calling function within (function() {...})(); Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2011-11-11 23:31 +0100
                Re: calling function within (function() {...})(); Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-12 00:38 +0100

csiph-web