Skip to content

Fix Proxy examples #91

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

leobalter
Copy link

the [[Get]] internal slot of Proxy calls the handler with target, P, and receiver as arguments.

the [[Call]] internal slot [calls the handler] with thisArgument and an argsList which is an Array made from the argumentsList. You don't need to use a rest parameter there.

the [[Get]] internal slot of Proxy [calls the handler](http://www.ecma-international.org/ecma-262/6.0/index.html#sec-proxy-object-internal-methods-and-internal-slots-get-p-receiver) with `target`, `P`, and `receiver` as arguments.

the [[Call]] internal slot [calls the handler] with `thisArgument` and an `argsList` which is an Array made from the argumentsList. You don't need to use a rest parameter there.
get: function (receiver, name) {
return `Hello, ${name}!`;
get: function (target, property, receiver) {
return `Hello, ${property}!`;

Choose a reason for hiding this comment

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

What about keeping "name", but change the parameters? Maybe use a different example that clarifies the use of this. For example:

var person = { name: "Alice" };
var handlers = {
    get: function (target, property, receiver) {
        if (property === "realName") {
            return target.name;
        } else if (property === "fakeName") {
            return "Really " + receiver.name;
        }
        return "Bob";
    }
};

var fakePerson = new Proxy(person, handlers);
fakePerson.name === "Bob" &&
fakePerson.realName === "Alice" &&
fakePerson.fakeName === "Really Bob";

@objectivezhou
Copy link

objectivezhou commented Jun 14, 2024 via email

@weinianhuan
Copy link

weinianhuan commented Jun 14, 2024 via email

@MehdiRaash
Copy link

LGTM

@weinianhuan
Copy link

weinianhuan commented Aug 9, 2024 via email

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

Successfully merging this pull request may close these issues.

6 participants