fns stores continuations.
gensym: make an array of 20 random characters (make an array of 20 #s, map each to a random character).
storefunc: continuation -> string, and store the continuation in fns, such that eval(string)==continuation
jsonk: make a query string from the url, the parameters supplied, and the continuation (change 'callback' to whatever the api calls it), and then add that script to the page, returning the url for debugging purposes.
you could also have a timeout after 30 seconds to say "something went wrong", and that might not be much more code, just set a timeout, and wrap k in jsonk to a function that first stops the delayed error message and then calls k, but that's an exercise for the reader.
Comments
What's $R and $H doing? I know Javascript, but I don't know all the cool frameworks very well.
Otherwise, this is mad cool.
it's a little kludgy, but here's how it goes:
fns stores continuations. gensym: make an array of 20 random characters (make an array of 20 #s, map each to a random character). storefunc: continuation -> string, and store the continuation in fns, such that eval(string)==continuation jsonk: make a query string from the url, the parameters supplied, and the continuation (change 'callback' to whatever the api calls it), and then add that script to the page, returning the url for debugging purposes.
you could also have a timeout after 30 seconds to say "something went wrong", and that might not be much more code, just set a timeout, and wrap k in jsonk to a function that first stops the delayed error message and then calls k, but that's an exercise for the reader.
but yeah, so
jsonk("http://api.search.yahoo.com/WebSearchService/V1/webSearch",{output:'json',appid:'YahooDemo',query:'britney'},function(r){alert(r.ResultSet.totalResultsAvailable)})
will pop up an alertbox that shows how many hits 'britney' gets on yahoo.
$R = Range object. http://www.sergiopereira.com/articles/prototype.js.html#Doll...
$H = Hash. http://www.sergiopereira.com/articles/prototype.js.html#Doll...