Skip to content
Permalink
Browse files
fix(compat): copy additional properties for functions bound via globa…
…lProperties (#4873)

close #4403
  • Loading branch information
LinusBorg committed Apr 13, 2022
1 parent c6eb3cc commit 1612971
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
@@ -356,7 +356,9 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
return desc.get.call(instance.proxy)
} else {
const val = globalProperties[key]
return isFunction(val) ? val.bind(instance.proxy) : val
return isFunction(val)
? Object.assign(val.bind(instance.proxy), val)
: val
}
} else {
return globalProperties[key]
@@ -285,6 +285,28 @@ describe('GLOBAL_PROTOTYPE', () => {
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 () => {
const Foo = Vue.extend()
Foo.prototype.$test = 1

0 comments on commit 1612971

Please sign in to comment.