Skip to content

Instantly share code, notes, and snippets.

@func09
Created March 5, 2009 19:14
Show Gist options
  • Save func09/74498 to your computer and use it in GitHub Desktop.
Save func09/74498 to your computer and use it in GitHub Desktop.
/**
* 関数クラスのユーティリティメソッド
* @author Mitsuru Haga <mitsuru.haga@gmail.com>
* @version 2009/03/02 23:10
*/
class com.func09.utils.FunctionUtil {
/**
* スコープ付き関数を取得する
* @param func
* @param target
* @return スコープを委譲したメソッドオブジェクト
*/
public static function bind( func:Function, target:Object ):Function{
return function(){
func.apply( target, arguments);
};
}
/**
* 遅延関数を取得する
* @param func
* @param duration
* @return 遅延実行されるメソッドオブジェクト
*/
public static function delay( func:Function, duration:Number ):Function{
return function(){
var id:Number = setInterval( func, duration, arguments );
var did:Number = setInterval( function(){ clearInterval(id); }, duration + 1 );
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment