Dynamic functions are a very useful feature of AS3 and JavaScript. Closures constantly come in handy for cleaner, more powerful code. Here’s a feature you might not know about them though.

As it turns out, you can add properties on to dynamic functions:

var f:Function = function():void{};
f["name"] = "Monkey";
trace(f["name"]); // prints "Monkey"

Using this trick you can go further customizing your Function, which is really more of a dynamically-created class. Consider adding this:

f["toString"] = function():String{return "function named " + f["name"]; };
trace(f); // prints "function named Monkey"

So if you’re an AS3 programmer longing for the old days of AS2 where you could dynamically add properties on to objects, you can do it with dynamic functions. This is also true with any dynamic class like Object, Dictionary, etc. It can be a very useful debugging feature too. Of course, JavaScript has always had this. Feel free to use it there too. Have fun!