闭包-柯里化

函数柯里化:预先将函数的某些参数传入,将其保存在内部函数中

function createNum(start) {
  return function (end) {
    return start += end ;
  }
}
var t= createNum(5);
console.log(t(3));  // 8
console.log(t(2)); // 10
应用:
UI局部刷新
function update(index) {
  return function (text) {
    $("div#"+ index).html(text); 
  }
}

ajax请求
function refresh(callback) {
  $.ajax({
    success:function (data) {
      callback(data);
    }
  })
}

 

原文地址:https://www.cnblogs.com/yuyedaocao/p/12060443.html