-
Notifications
You must be signed in to change notification settings - Fork 4
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
Comments
What is this used for? |
Changing the context in getters. |
Yeah, but why? I'm not arguing against changing it, I'm just wondering what is the use case. I understand why this is important for functions, but normally property access is so "bound/connected" to the object, in having trouble seeing where this is useful. Perhaps being able to "steal" something like Array's length.
…Sent from my iPhone
On May 19, 2017, at 8:36 PM, Matthew Phillips ***@***.***> wrote:
Changing the context in getters.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
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 Just opened this for discussion, no reason to add until a clear use-case is present. |
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); |
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.The text was updated successfully, but these errors were encountered: