获取setInterval定时器内部函数返回值

var myTimer = function (callback) {
  var height = 10;
  var flag = true;
  setInterval(function () {
    if (flag) {
      height--;
      if (height <= -10) {flag = false;}
    } else {
      height++;
      if (height >= 10) {flag = true;}
    }
    callback(height);
  }, 200);
};

myTimer(function (val) {
  console.log(val);
});

 

posted @ 2020-09-25 11:25  simple-love  阅读(1269)  评论(0编辑  收藏  举报