setTimeOut的第三个参数

setTimeOut(function,time,arg)

  • function:要执行的函数
  • time:延时,毫秒
  • arg:传给function的参数

function test(){
    console.log(arguments);
}
setTimeout(test,1000,1,2,3,4)

 

可以复制看下打印结果。

第三个参数以及后面的各个参数会被传入到function里面,这对promise来说很有用(偷过来的一个例子)

function timeout(ms) {
  return new Promise((resolve, reject) => {
    setTimeout(resolve, ms, 'done');
  });
}

timeout(100).then((value) => {
  console.log(value);
});

  

posted @ 2017-05-12 17:37  IsaacYoung  阅读(407)  评论(0)    收藏  举报