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
Fix Proxy examples
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.
  • Loading branch information
leobalter committed Jul 30, 2015
commit eb4e2c998c38b6b9e857311e2e829c155b1b3214
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