Skip to content

Latest commit

 

History

History
21 lines (16 loc) · 426 Bytes

3.5.3-闭包的抽象.md

File metadata and controls

21 lines (16 loc) · 426 Bytes
  • 闭包为javascript提供了私有访问,这是一种抽象的方法
  • 可以在创建函数时,做一些配置
function plucker(FIELD) {
  return function(obj) {
    return (obj && obj[FIELD])
  }
}

var best = {title : "Infinite Jest, author: "DFW"}
var getTitle = plucker("title")

plucker 函数操作数组的例子

var books = [{title:1}, {title:2}]
var third = plucker(2)