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

Allow providing the this context to getValue and getKeyValue #8

Open
matthewp opened this issue May 19, 2017 · 5 comments
Open

Allow providing the this context to getValue and getKeyValue #8

matthewp opened this issue May 19, 2017 · 5 comments

Comments

@matthewp
Copy link
Contributor

Reflect.get takes a 3rd argument, the this value that will be passed into getters. This is useful. Would be nice to have in the can-reflect APIs as well.

@justinbmeyer
Copy link
Contributor

What is this used for?

@matthewp
Copy link
Contributor Author

Changing the context in getters.

@justinbmeyer
Copy link
Contributor

justinbmeyer commented May 20, 2017 via email

@matthewp
Copy link
Contributor Author

I don't have a specific use-case in can-reflect at the moment. In regular old js, when overriding a Proxy getter you would want this feature so that if calling into the target getter the Proxy object would be the value of this (so if any property access happens there it also goes through the Proxy).

Just opened this for discussion, no reason to add until a clear use-case is present.

@matthewp
Copy link
Contributor Author

matthewp commented May 22, 2017

Here's some pseudocode where this would be useful with Proxys. Might help think of a where this could also be important with can-reflect:

var target = {
  foo: "bar"
};
Object.defineProperty(target, "baz", {
  get: function(){
    return this.foo;
  }
});

var p = new Proxy(target, {
  get: function(target, prop){
    // Count all observations
    Observation.add(target, prop);

    // This means that the `foo` accessor will be observed
    return Reflect.get(target, prop, p);
  }
});

// This should count 2 observations
console.log(p.baz);

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