fix(compat): copy additional properties for functions bound via globalProperties (#4873)

close #4403
This commit is contained in:
Thorsten Lünborg 2022-04-13 11:53:07 +02:00 committed by GitHub
parent c6eb3cccce
commit 1612971471
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View File

@ -356,7 +356,9 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
return desc.get.call(instance.proxy) return desc.get.call(instance.proxy)
} else { } else {
const val = globalProperties[key] const val = globalProperties[key]
return isFunction(val) ? val.bind(instance.proxy) : val return isFunction(val)
? Object.assign(val.bind(instance.proxy), val)
: val
} }
} else { } else {
return globalProperties[key] return globalProperties[key]

View File

@ -285,6 +285,28 @@ describe('GLOBAL_PROTOTYPE', () => {
delete Vue.prototype.$test delete Vue.prototype.$test
}) })
test.only('functions keeps additional properties', () => {
function test(this: any) {
return this.msg
}
test.additionalFn = () => {
return 'additional fn'
}
Vue.prototype.$test = test
const vm = new Vue({
data() {
return {
msg: 'test'
}
}
}) as any
expect(typeof vm.$test).toBe('function')
expect(typeof vm.$test.additionalFn).toBe('function')
expect(vm.$test.additionalFn()).toBe('additional fn')
delete Vue.prototype.$test
})
test('extended prototype', async () => { test('extended prototype', async () => {
const Foo = Vue.extend() const Foo = Vue.extend()
Foo.prototype.$test = 1 Foo.prototype.$test = 1