`
zhangyaochun
  • 浏览: 2652507 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

underscore的Function之delay

阅读更多

 

 

  delay

 

   _.delay(function,wait,[*arguments])

 

  •  类似setTimeout  等待参数wait后调用function
  • 如果传递了可选的参数arguments ,当function执行的时候,传递给它

  源码

 

_.delay = function(func,wait){

     //看看有没有第三个参数
     var args = Array.prototype.slice.call(arguments,2);

     return setTimeout(function(){

              //这边调用的时候传一下args,不管有没有
              return func.apply(null,args);


      },wait);    

};

 

 

分享到:
评论

相关推荐

    underscore源码学习计划

    _.defer()和_.delay()用于延迟函数执行,而_.throttle()和_.debounce()则用于限制函数的执行频率,防止过于频繁的调用,提高性能。其中,_.debounce()常用于事件处理,如窗口滚动事件。 六、模板引擎 _.template()...

    深入解析Backbone.js框架的依赖库Underscore.js的作用

    - **功能函数类**:包括`bind`, `partial`, `memoize`, `delay`, `defer`, `throttle`, `debounce`, `wrap`等,用于函数操作和优化。 - **对象类**:提供了`keys`, `values`, `pairs`, `invert`, `pick`, `omit`, `...

    30_手写防抖节流-深拷贝-事件总线1

    function debounce(fn, delay) { let timer; return function() { clearTimeout(timer); timer = setTimeout(fn, delay); } } ``` 节流函数(Throttle) 节流函数的概念最早出现在流体流动中,用于限制流体的...

    javascript中的throttle和debounce浅析

    function throttle(fn, delay) { let timeoutId = null; return function() { const context = this; const args = arguments; if (!timeoutId) { timeoutId = setTimeout(() => { fn.apply(context, args); ...

    用HTML5CSS3实现媲美原生应用的交互体验_尤雨溪

    `transition: property duration timing-function delay;` 例如: ```css .transition { transition: all 1s linear; } ``` 需要注意的是,当使用`all`作为属性值时,要格外小心,因为它会影响所有样式的变化。 #...

    jquery用户连续输入事件

    例如,`debounce` 和 `throttle` 方法在 Lodash 和 Underscore.js 库中被广泛使用,它们可以帮助你控制函数的执行频率。`debounce` 用于确保函数在最后一次调用后的特定延迟时间后再执行,而 `throttle` 则是限制...

    prototype1.4中文手册

    - **对 Function 扩展**:增加了 `bind`, `bindAsEventListener`, `defer`, `delay` 等方法。 - **对 String 的扩展**:添加了 `interpolate`, `traverse`, `gsub`, `gsub!`, `split`, `camelize`, `capitalize`, `...

    原生JS实现图片懒加载(lazyload)实例

    function throttle(func, delay) { let timeoutId; return function() { const context = this; const args = arguments; clearTimeout(timeoutId); timeoutId = setTimeout(function() { func.apply(context...

    Lodash

    Lodash 提供了多种类型检查方法,如 `isString`, `isArray`, `isFunction`, `isObjectLike` 等,用于确定变量的类型,这对于确保代码的健壮性和兼容性至关重要。 5. **实用工具** Lodash 还包含一些实用的工具...

Global site tag (gtag.js) - Google Analytics