4 messages in com.googlegroups.google-gadgets-apiRe: Extra arguments for f in _IG_Fetc...
FromSent OnAttachments
gurkesaft23 May 2006 21:17 
YLA G24 May 2006 05:53 
Justin McConnell07 Jun 2006 17:45 
Jack Sankey07 Jun 2006 20:13 
Subject:Re: Extra arguments for f in _IG_FetchContent(url, f)
From:Jack Sankey (jack@gmail.com)
Date:06/07/2006 08:13:04 PM
List:com.googlegroups.google-gadgets-api

Thanks. That should work quite well!

On 6/7/06, Justin McConnell <bool@gmail.com> wrote:

One option is to use a function closure. That way the inner function has access to the variables of the outer function: for(n=0; n<=3; n++) { _IG_FetchContent(url[n], function() { // I can see everything that is visible outside the _IG_FetchContent call }); }

Another option is to set n as a global variable so it is in scope of every function. Looking at your code, unless you defined var n earlier, n is a global and you should be able to see it in function f already. If you did go this route, you would want to rename n to something more unique -- n is such a simple variable name you might have namespace collisions with other variables on the page.

Personally, I'd lean towards a function closure since global variables are aguablely insecure and the source of potential bugs.

gurkesaft wrote:

Hello,

Is it possible to call _IG_FetchContent(url, f) with additional arguments sent to f? I need to send f more information than the URL string returned by the fetch. Ideally, I'd like to be able to do something like this

for(n=0; n<=3; n++) { _IG_FetchContent(url[n], f(__returned_string__, n)) }

or something, so that f can know what n is as well as the content string. I really have no clue how to do something like this.

Can anyone help? If not, is there a code structuring philosophy I should change? I'd use globals, but this function seems to run in a thread, finishing in its own time, so that the above code quickly loops before f is even called the first time (and n changes).

I'm thinking of **kwargs from python as I write this :)

Thanks, -Jack