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

Fix Proxy examples #91

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,8 @@ Proxies enable creation of objects with the full range of behaviors available to
// Proxying a normal object
var target = {};
var handler = {
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";

}
};

Expand All @@ -408,7 +408,7 @@ p.world === 'Hello, world!';
// Proxying a function object
var target = function () { return 'I am the target'; };
var handler = {
apply: function (receiver, ...args) {
apply: function (thisArg, args) {
return 'I am the proxy';
}
};
Expand Down