Function Returns a Function


appendExclamation("actionsnippit")("dot")("com")("is")("live");

function appendExclamation(str:String):Function{
  trace(str + "! ");
  return appendExclamation;
}

/* outputs:
actionsnippit!
dot!
com!
is!
live!
*/

This technique allows you to call a function more than once on one line. I first saw this used in the source files from a talk at flashcoders ny… I didn’t attend the talk, but stumbled on this interesting blog post awhile back http://www.flashcodersny.org/wordpress/?p=166.

This is a fun technique to use, I’ve found some unusual uses for it already… some of which you’ll see in later posts….