Skip to content

Commit 783101b

Browse files
committed
调整
1 parent b8ad566 commit 783101b

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

Currying.js

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// 柯里化
22
// 严格意义上的柯里化应该只接收一个参数
3-
3+
// 参数复用。本质上是降低通用性,提高适用性。
44

55

66
// 普通函数
@@ -56,4 +56,39 @@ function add() {
5656
console.log(add(1)(2)(3))
5757
console.log(add(1, 2, 3)(4))
5858
console.log(add(1)(2)(3)(4)(5))
59-
console.log(add(2, 6)(1))
59+
console.log(add(2, 6)(1))
60+
61+
62+
function sub_curry(fn){
63+
return function(){
64+
return fn()
65+
}
66+
}
67+
68+
function curry(fn, length){
69+
length = length || 4;
70+
return function(){
71+
if (length > 1) {
72+
return curry(sub_curry(fn), --length)
73+
}
74+
else {
75+
return fn()
76+
}
77+
}
78+
}
79+
80+
var person = [{name: 'kevin'}, {name: 'daisy'}]
81+
82+
var name = person.map(function(item){
83+
return item.name
84+
})
85+
86+
console.log(name) // ['kevin','daisy']
87+
88+
var prop = curry(function(key,oj){
89+
return obj[key]
90+
})
91+
92+
var name = person.map(prop('name'))
93+
94+
console.log(name) // ['kevin','daisy']

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,20 @@
6767
>
6868
> // H,w are y,u d,ing t,day?
6969
70+
##### reduce() 方法接收一个函数作为累加器,数组中的每个值(从左到右)开始缩减,最终计算为一个值。
71+
72+
+ reduce() 方法接收一个函数作为累加器,数组中的每个值(从左到右)开始缩减,最终计算为一个值。
73+
74+
75+
##### concat() 方法用于连接两个或多个字符串。
76+
77+
`var str1="Hello ";
78+
var str2="world!";
79+
var str3=" Have a nice day!";
80+
var n = str1.concat(str2,str3);
81+
// Hello world! Have a nice day!`
82+
83+
7084

7185

7286

0 commit comments

Comments
 (0)