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


Groups > comp.lang.javascript > #16137

Anonymous function in closure

Date 2012-09-24 09:32 +1000
From Andrew Poulos <ap_prog@hotmail.com>
Newsgroups comp.lang.javascript
Subject Anonymous function in closure
Message-ID <8ZOdnd6tG7eeAcLNnZ2dnUVZ_vGdnZ2d@westnet.com.au> (permalink)

Show all headers | View raw


If I have a closure like this:

function foo(a) {
   return function() {
     // do something with a
   };
}

var bar = foo(10);

document.getElementById('a').onclick = bar;


Why doesn't
   var bar = foo(10);
cause the anonymous function in 'foo' to be executed but clicking on 'a' 
does?

Andrew Poulos

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


Thread

Anonymous function in closure Andrew Poulos <ap_prog@hotmail.com> - 2012-09-24 09:32 +1000
  Re: Anonymous function in closure David Mark <dmark.cinsoft@gmail.com> - 2012-09-23 17:09 -0700
    Re: Anonymous function in closure Andrew Poulos <ap_prog@hotmail.com> - 2012-09-24 14:20 +1000
      Re: Anonymous function in closure David Mark <dmark.cinsoft@gmail.com> - 2012-09-24 00:10 -0700
      Re: Anonymous function in closure Gene Wirchenko <genew@ocis.net> - 2012-09-24 11:09 -0700
        Re: Anonymous function in closure Gene Wirchenko <genew@ocis.net> - 2012-09-24 13:27 -0700
  Re: Anonymous function in closure webnician@gmail.com - 2012-09-24 15:18 -0700

csiph-web