You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
459 B
20 lines
459 B
5 months ago
|
var slice = require('./slice')
|
||
|
|
||
|
/**
|
||
|
* 该方法和 setTimeout 一样的效果,区别就是支持上下文和额外参数
|
||
|
*
|
||
|
* @param {Function} callback 函数
|
||
|
* @param {Number} wait 延迟毫秒
|
||
|
* @param {*} args 额外的参数
|
||
|
* @return {Number}
|
||
|
*/
|
||
|
function delay (callback, wait) {
|
||
|
var args = slice(arguments, 2)
|
||
|
var context = this
|
||
|
return setTimeout(function () {
|
||
|
callback.apply(context, args)
|
||
|
}, wait)
|
||
|
}
|
||
|
|
||
|
module.exports = delay
|