1-js/06-advanced-functions/11-currying-partials#113
Merged
leviding merged 8 commits intojavascript-tutorial:zh-hansfrom Jun 8, 2018
Merged
1-js/06-advanced-functions/11-currying-partials#113leviding merged 8 commits intojavascript-tutorial:zh-hansfrom
leviding merged 8 commits intojavascript-tutorial:zh-hansfrom
Conversation
Contributor
Author
|
@leviding 翻译完成 |
Contributor
|
@leviding 校对认领。 |
zhongdeming428
approved these changes
Jun 6, 2018
| --- | ||
|
|
||
| # Partial application for login | ||
| # 偏函数在登陆中的应用 |
| ``` | ||
|
|
||
| It allows to bind context as `this` and starting arguments of the function. | ||
| 可以看出,它允许将上下文绑定到 `this`,以及函数的前几个参数。 |
Contributor
There was a problem hiding this comment.
上下文 => context
我觉得这里context不翻译比较好,因为代码中参数名为context,如果这里翻译为上下文,可能有些刚入门的童鞋不知道是指的代码中的context,当然我只是建议哈,原翻译没有任何问题。
Contributor
Author
There was a problem hiding this comment.
嗯,我觉得这个系列看到这里,应该都知道上下文了,所以直接译出来了。
| 请注意通常我们不在这里使用 `this`,但是 `bind` 需要一个值,我们必须传入,那么可以是 `null` 这样的值。 | ||
|
|
||
| The function `triple` in the code below triples the value: | ||
| 以下代码中的 `triple` 函数对一个值做三次方运算: |
| ``` | ||
|
|
||
| Let's curry it! | ||
| 让我们开始柯里化! |
| 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` 函数。虽然再次调用。我们要么得到一个新的偏函数(如果参数数量不够),要么,最终得到结果。 |
Contributor
There was a problem hiding this comment.
否则 => 当传入的 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` 函数。虽然再次调用。我们要么得到一个新的偏函数(如果参数数量不够),要么,最终得到结果。 |
| ## 总结 | ||
|
|
||
| - 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. | ||
| - 当我们确定一个函数的一些参数时,返回的函数(更加特定)被称为**偏函数**。 |
Contributor
There was a problem hiding this comment.
We can use `bind` to get a partial, but there are other ways also.
这一句没有翻译。
可以翻译为:
我们可以使用 `bind` 来获取偏函数,但是也有其他方式获取。
Contributor
|
@allenlongbaobao @leviding 校对完成。 |
Contributor
Author
|
@leviding @zhongdeming428 修改完毕 |
leviding
approved these changes
Jun 8, 2018
Member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
翻译完毕 resolve #91