-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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(compat): don't bind function from globalProperties to the current istance if it has additional properties #4873
Conversation
This comment has been minimized.
This comment has been minimized.
I'm can't follow ... |
Sorry for my broken English, I misunderstood something yesterday.
Why not do so? Or perhaps we could simply use |
I also think copying any existing self properties would be safer - the assumption that "a function with extra properties doesn't need access to Copying with |
Agreed, will make the necessary change |
No idea why the PR test runs fail, and the push ones run fine ... 🧐 |
It seems caused by #4807🤔 |
Yeah, it's been reverted in latest master - @LinusBorg can you rebase and add a test case? |
… istance if it has additional properties close #4403
63f9b87
to
0ff055c
Compare
Done |
published? which version? |
Problem
In Vue 2, we add global properties to the Vue prototype:
This will automatically make
this
in such a function point ot the component instance.In Vue 3's compat behaviour, we need to call
fn.bind(proxy)
to achieve a similar behaviour.But this poses a problem for funtions that 1) don't need access to the component proxy and 2) have additional properties, which are lost during
fn.bind()
:Solution
To accomodate fort his common usecase, I added a check for
Object.keys(val).length === 0
. The reasoning being: if the function has additional properties, it is almost surely an external library and not a plain function meant to be used as an instance method.Alternatives
We could alternatively re-apply all of the custom properties that we found with
Object.keys()
onto the new bound function. But I'm not convinced the effort and additional code would be worth the gains.close #4403