-
Notifications
You must be signed in to change notification settings - Fork 1.2k
1-js/06-advanced-functions/11-currying-partials #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@leviding 翻译完成 |
@leviding 校对认领。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
翻译得非常非常nice。
@@ -2,13 +2,13 @@ importance: 5 | |||
|
|||
--- | |||
|
|||
# Partial application for login | |||
# 偏函数在登陆中的应用 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
登陆 => 登录
|
||
```js | ||
let bound = func.bind(context, arg1, arg2, ...); | ||
``` | ||
|
||
It allows to bind context as `this` and starting arguments of the function. | ||
可以看出,它允许将上下文绑定到 `this`,以及函数的前几个参数。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
上下文 => context
我觉得这里context
不翻译比较好,因为代码中参数名为context
,如果这里翻译为上下文,可能有些刚入门的童鞋不知道是指的代码中的context
,当然我只是建议哈,原翻译没有任何问题。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
嗯,我觉得这个系列看到这里,应该都知道上下文了,所以直接译出来了。
|
||
The function `triple` in the code below triples the value: | ||
以下代码中的 `triple` 函数对一个值做三次方运算: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
三次方 => 三倍
|
||
```js | ||
function log(date, importance, message) { | ||
alert(`[${date.getHours()}:${date.getMinutes()}] [${importance}] ${message}`); | ||
} | ||
``` | ||
|
||
Let's curry it! | ||
让我们开始柯里化! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
开始 => 将它
1. Call now: if passed `args` count is the same as the original function has in its definition (`func.length`) or longer, then just pass the call to it. | ||
2. Get a partial: otherwise, `func` is not called yet. Instead, another wrapper `pass` is returned, that will re-apply `curried` providing previous arguments together with the new ones. Then on a new call, again, we'll get either a new partial (if not enough arguments) or, finally, the result. | ||
1. 立刻执行:当传入的 `args` 的长度和初始函数中所定义的(`func.length`)相同或者更长,那么直接将它传入需要执行的函数。 | ||
2. 得到一个偏函数:否则,`func` 暂时不被调用。相反,返回另外一层封装 `pass`,其中,将之前传入的参数合并新传入的参数一起应用于 `curried` 函数。虽然再次调用。我们要么得到一个新的偏函数(如果参数数量不够),要么,最终得到结果。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
否则 => 当传入的 args
的长度小于初始函数中所定义的(func.length
)
1. Call now: if passed `args` count is the same as the original function has in its definition (`func.length`) or longer, then just pass the call to it. | ||
2. Get a partial: otherwise, `func` is not called yet. Instead, another wrapper `pass` is returned, that will re-apply `curried` providing previous arguments together with the new ones. Then on a new call, again, we'll get either a new partial (if not enough arguments) or, finally, the result. | ||
1. 立刻执行:当传入的 `args` 的长度和初始函数中所定义的(`func.length`)相同或者更长,那么直接将它传入需要执行的函数。 | ||
2. 得到一个偏函数:否则,`func` 暂时不被调用。相反,返回另外一层封装 `pass`,其中,将之前传入的参数合并新传入的参数一起应用于 `curried` 函数。虽然再次调用。我们要么得到一个新的偏函数(如果参数数量不够),要么,最终得到结果。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
相反 => 取而代之的是
|
||
- When we fix some arguments of an existing function, the resulting (less universal) function is called *a partial*. We can use `bind` to get a partial, but there are other ways also. | ||
- 当我们确定一个函数的一些参数时,返回的函数(更加特定)被称为**偏函数**。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use `bind` to get a partial, but there are other ways also.
这一句没有翻译。
可以翻译为:
我们可以使用 `bind` 来获取偏函数,但是也有其他方式获取。
@allenlongbaobao @leviding 校对完成。 |
@leviding @zhongdeming428 修改完毕 |
翻译完毕 resolve #91