Skip to content

Comment on Anyone using a functional programming style in their Javascript?parent

Comments

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.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.