Main menu:


Site search

Archives

RSS Arjen's Friendfeed

RSS Richard's del.icio.us links

RSS Maurits' Stumbled Items

Curry: partial functions in Actionscript 3

I needed curry() and bind() in Actionscript 3, because I was porting a Javascript application that was built using PrototypeJS 1.6 to Flex and the application heavily used these functions. I came up with the following Actionscript / Flex code:

bindAndCurry.as

package
{ public function bindAndCurry(...a):Function
  { return function(...b):*
    { return a.shift().apply(a.shift(), a.concat(b))
    }
  }
}
BindAndCurryTest.as
package
{ import flash.display.Sprite;
  public class BindAndCurryTest extends Sprite
  { private function print(message:String):void
    { trace(message);
    }
    public function BindAndCurryTest()
    { var f:Function = bindAndCurry(print,this,'hello world!');
      f();
    }
  }
}
Maurits

Write a comment