Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

return func.apply(this, arguments);
};
```
Expand Down