Skip to content
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

86 页 括号错误,注释描述会让人产生误解 #35

Open
daixiangtian opened this issue Jun 3, 2022 · 1 comment
Open

86 页 括号错误,注释描述会让人产生误解 #35

daixiangtian opened this issue Jun 3, 2022 · 1 comment

Comments

@daixiangtian
Copy link

daixiangtian commented Jun 3, 2022

6759ae914327d2b3dba9d1802e36090
image
Reflect.get始终输出的是1

@Zen-QC
Copy link

Zen-QC commented Jun 4, 2022

这里的 receiver 类似于 getter 函数调用时的 this 指向:

const obj = {
    _foo: 1,
    get foo() {
        //  此时打印一下 this 值可以看到:
        console.log(this);     //  { _foo: 2 }
        return this._foo;
    },
};

console.log(Reflect.get(obj, "foo", { _foo: 2 }));  // 2

你直接在 getter 函数中 return 1,这里的 receiver 就不起效果了。

(PS. getter 函数不应与属性重名,书中的这个例子将 “foo” 修改为 “_foo” 更合适一些)
重名会导致的问题:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants