Earlier quoted context omitted.
I like this question, and I've got something that works, but I'm not sure it's the prefered solution. function say(arg) { return function(word) { alert(arg + " " + word); }; } It solves "hello world", but wouldn't work for something like say("dogs")("and")("cats"). Are you expecting an arbitrary number of function returns?
Yep, that is exactly the solution I would be looking for. I would be blown a way if someone came up with solution that could handle arbitrary function returns. My friend actually wrote an interesting article on the subject. Here's the link if you're interested: http://msdn.microsoft.com/en-US/scriptjunkie/gg575560.aspx
var say = (function() {
var savedArgs = [];
return (function recurse () {
if (arguments.length) {
for (var i=0, arg; arg=arguments[i]; i++) {
savedArgs.push(arg);
}
return recurse;
} else {
alert(savedArgs.join(' '));
savedArgs = [];
}
});
})();// e.g. say('Hello')('World')('!!')();
// --> alerts "Hello World !!"