函数扩展

1.throttle

函数节流器,用于防抖等操作。

接收参数:

参数 必填 描述
fn 当满足触发条件后,会执行的函数
delay 当有触发动作时,顺延delay毫秒执行
least 当有触发动作时,least毫秒后必定执行

示例:

var resize = function () {
     console.log('resize')
   }
window.onresize = _.throttle(resize, 2000, 5000)

2.日期格式化

接收参数:

参数 必填 描述
date 时期格式,比如new Date()
format 需要返回的时间模型 比如: yyyy/mm/dd hh:mm:ss 或 yyyy-mm-dd hh:mm:ss

示例:

_.formatDate(new Date(), 'yyyy-MM-dd hh:mm:ss') // => 2017-7-21 19:28:30
_.formatDate(new Date(), 'yyyy/MM/dd') // => 2017/7/21

results matching ""

    No results matching ""