myUnderscore
  • myUnderscore
  • 基础篇-将函数挂载到'_'上
    • 函数式风格调用
    • 实现面向对象风格调用。
    • 链式调用
  • 类数组与最大安全数
  • 函数判断与Js中的’&& ||‘+假值
  • 字符串反转
  • 高阶函数篇
    • every和some
    • sortBy和闭包
    • 用于调试的tap()
    • unary和parseInt的经典大坑
    • once 和 它牵扯出的this
    • this
      • 调用位置和绑定规则
      • 隐式绑定与隐式丢失
      • 显式绑定与硬绑定
      • new绑定和优先级
      • 被忽略的this和更安全的this用法
      • 软绑定和箭头函数的this
      • 遗留问题:硬绑定无法被改绑的原理是什么?
  • memoized 函数
  • forEach,map 和 reduce
  • filter 过滤器 和 zip 合并数组
  • flatten数组扁平化
  • 避免XXS攻击的字符转义(escape)和反转义(unescape)
Powered by GitBook
On this page

Was this helpful?

字符串反转

字符反转 reverse()

_.reverse = function(string){
    return string.split('').reverse().join('');
}

这是一种取巧的做法,过程相当于

'1234'=>['1','2','3','4']=>['4','3','2','1']=>'4321'
Previous函数判断与Js中的’&& ||‘+假值Next高阶函数篇

Last updated 5 years ago

Was this helpful?