标签:
函数式编程,属于编程范式的一种
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