前端常见手撕代码

柯里化

把接受多个参数的函数变换成接受一个单一参数(最初函数的第一个参数)的函数,并且返回接受余下的参数而且返回结果的新函数的技术。
柯里化的作用大致有三个:

  • 延迟执行
  • 参数复用
  • 动态生成函数

数组扁平化

手写bind

使用柯里化写

Function.prototype.bind = function (context) {
    var _this = this
    var args = Array.prototype.slice.call(arguments, 1)
 
    return function() {
        return _this.apply(context, args)
    }
}

promise.all

用border画三角形

手写防抖/节流

将横杠转为驼峰形式

解析URL

圣杯布局

原文地址:https://www.cnblogs.com/whisperbb/p/14550369.html