> > From: DaveG > > > > If I use the jQuery document.ready shortcut to delay the > > definition of a javascript function test(), what is the correct > > way to reference test()? > > > > This does not work: > > jQuery ( function() { function test() {alert('here')} } ); > > test; // assume that test is defined at this point... > > > > I thought it might be something like this, but no joy there either: > > localJQ = jQuery ( function() { function test() {alert('here')} } ); > > localJQ.test;
You're making it too complicated there, Dave. :-) function test() { alert('here'); }; jQuery( test ); test; // test is now defined, but (usually) not yet executed > From: Erik Beeson > > Why would you want to delay the definition of a function? Lots of reasons. I just wrote some code exactly like Dave's. I had a test page that ran a function (coincidentally also called test) at load time. Then I added a "Repeat" button to re-run the same test. -Mike