Skip to content

Fix:示例代码错误 #1239

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

Closed
wants to merge 1 commit into from
Closed

Conversation

Allen-su
Copy link

@Allen-su Allen-su commented Jan 1, 2025

目标章节:1-js/06-advanced-functions/09-call-apply-decorators
呼叫转移的最简形式示例代码,其中的函数缺少入参,会使其他人产生疑问
在本文的总结部分也有类似的问题,考虑到使用的是 original ,它可以指代原始对象函数,看上去可以不做修改

当前上游最新 commit:此处填写本项目英文版 https://github.com/javascript-tutorial/en.javascript.info 的最新 commit,例如 b03ca00

本 PR 所做更改如下:

文件名 参考上游 commit 更改(理由)
article.md a23882d 修改部分错误

注意,参考上游 commit 是指你所修改的文件,在英文仓库中同名文件的对应 commit,即你此次提交的修改的依据。如果本 PR 你只是提交一个文字或者语句优化,并非根据上游英文仓库的修改而提交的更新,则请填无。

javascript 课程的【函数进阶内容】章节,【装饰器模式和转发,call/apply】小节中呼叫转移的最简形式示例代码,其中的函数缺少入参,会使其他人产生疑问
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@Allen-su Allen-su changed the title Update article.md Fix:示例代码错误 Jan 1, 2025
@@ -319,7 +319,7 @@ func.apply(context, args);
这是它的最简形式:

```js
let wrapper = function() {
let wrapper = function(func) {
Copy link
Member

@songhn233 songhn233 Jan 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里如果加入参的话需要增加一个闭包

原文里意图是把 wrapper 当作 func 一样使用,所以 apply 这里有个 arguments 的透传。即 fn(xxx) 等同于 wrapper(xxxx),这么改 arguments 读了 func 又作为参数传给了自己就不对了

传 func 的话就应该是

let fn = function(func) {
  function wrapper() {
     return func.apply(this, arguments);
  }
  return wrapper;
};

之后通过 fn(x) 得到 x 的 wrapper

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个例子主要还是想用 wrapper 的 apply 来说明执行和 func 一样,所以 wrapper 的 arguments 直接透传给了 fn

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个例子主要还是想用 wrapper 的 apply 来说明执行和 func 一样,所以 wrapper 的 arguments 直接透传给了 fn

确实是这样,我理解错了,这里本意是一个用于返回的包装器

@javascript-translate-bot

Please make the requested changes. After it, add a comment "/done".
Then I'll ask for a new review 👻

3 similar comments
@javascript-translate-bot

Please make the requested changes. After it, add a comment "/done".
Then I'll ask for a new review 👻

@javascript-translate-bot

Please make the requested changes. After it, add a comment "/done".
Then I'll ask for a new review 👻

@javascript-translate-bot

Please make the requested changes. After it, add a comment "/done".
Then I'll ask for a new review 👻

@Allen-su Allen-su closed this Jan 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants