码迷,mamicode.com
首页 > 其他好文 > 详细

函数式编程

时间:2015-09-05 06:33:15      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:

函数式编程,属于编程范式的一种

1 函数是第一公民,可以返回值,也可以作为其他函数的参数

//console是一个函数
function con(v){
  console.log(v)
}
// execute 也是一个函数
function execute(fn){
  fn(1)
}
//将con函数作为参数传进execute函数
execute(con) // 1

2 接近自然语言的写法

  晓池吃完饭然后就去洗澡 可以表现为eat().bathe()

// 吃饭函数
function eat(eat){
  this.e = eat;
  return this;
}
// 洗澡函数
function bathe(bathe){
  this.b = bathe;
  return this;
}

var person = eat("晓池在吃饭").bathe("晓池去洗澡了");
console.log(person.e) // 晓池在吃饭
console.log(person.b)  // 晓池去洗澡了

 

函数式编程

标签:

原文地址:http://www.cnblogs.com/mimeay/p/4782657.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!