Check out "Do you speak JavaScript?" - my latest video course on advanced JavaScript.
Language APIs, Popular Concepts, Design Patterns, Advanced Techniques In the Browser

Delegation in AS3

I just can't code without delegation. I'm using it every day and wanted to share this method with you.
Here is the class:
 package {
    public class Delegate {
      public static
      function create(handler: Function, ...args): Function {
        return function (...innerArgs): void {
          handler.apply(this, innerArgs.concat(args));
The usage:
import flash.utils.setTimeout;
    setTimeout(Delegate.create(func, "param1text", "param2text"), 1000);
    function func(param1: String, param2: String): void {
      trace("func param1=" + param1 + " param2=" + param2);
And the result of the code:
func param1=param1text param2=param2text
If you enjoy this post, share it on Twitter, Facebook or LinkedIn. To leave a comment go here.