LoginSignup
1

More than 5 years have passed since last update.

JavaScriptのスニペット

Last updated at Posted at 2016-12-21

第一引数で与えた関数がtrueを返すまで、
第二引数の関数の実行を待つ関数。

function(func, callback, context){
 var args = _.toArray(arguments).slice(3);
 var timer = null;
 var ifunc = function(){
  if(func.apply(context, args)){
   if(!context){
    context = null;
   }
   if(timer){
    clearInterval(timer);
   }
   callback.apply(context, args);
   return true;
  }
  return false;
 };
 if(!ifunc()){
  timer = setInterval(ifunc, 50);
 }
 ifunc = null;
 return timer;
}

こーゆーのもうあるとか、こうしたほうがいいとかあったら教えてほしいなぁ

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1