-
Notifications
You must be signed in to change notification settings - Fork 25
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
Can you change the this
with call
and apply
?
#52
Comments
Actually reading the entire readme and I'm really unsure, especially given the semantics: https://github.com/tc39/proposal-partial-application#semantics How can I partially apply a function who's |
I would assume that |
Thanks, that's my interpretation after rereading the semantics as well. Could you create an unbound version some how? Maybe like this? const introduceBob = bob.introduce.call~(?);
introduceBob.call(barbara); |
Yes, but in that case it'd be |
If you want it to work with |
Hm, I'm a little confused, that doesn't use this new syntax proposal. Are you saying that you can't use this new syntax and then use call/apply on the created function to pass the |
I think what @ljharb is getting at is your example would be this, const introduceBob = bob.introduce.call~(?);
introduceBob(barbara); because edit: I might be wrong as I am just a random dude on the internet. |
Right you can't use this proposal's syntax, and end up with a normal function whose receiver can be dynamically changed via .call/.apply |
Ok, thanks for the clarity there. Then @ashwell My example was taken from the readme which is: const bob = {
name: "Bob",
introduce() {
console.log(`Hello, my name is ${this.name}.`);
}
}; This function can have call/apply used on it. From the readme it sounded like the proposal wanted to fix the issue with .bind() that you need to know the So I guess this thread should turn into a request that this feature be considered. |
I think the answer is that you can, but it was unclear to me from the examples. For example:
What if you do:
I assume the
this
inintroduce
refers to barbara and not bob, correct?The text was updated successfully, but these errors were encountered: