2ming / Demo

前端的一些小demo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

f(1)(2)实现

2ming opened this issue · comments

commented

方法一

function f(a,b){
  return function(b){
        return a + b;
  }
}
f(1)(2) // => 3
// 利用闭包在第一次调用的时候创建a

方法二

function f(a){
  f.add = function(x,y){
   return x + y
  }
  return f.add.bind(null, a)
}
f(2)(3) // => 5
//利用bind改变this,参数柯里化