.call, .apply, .bind methods of Function.prototype don't work for functions once defined as methods of Vue instance in .vue file.
I'm using @vue/cli project, compiled with vue-cli-service serve.
Here's reduced example of code, which can be placed in any Vue single-file component definition.
methods: {
foo() {
console.log(this);
}
},
created() {
this.foo.call({ bar: 42 });
this.foo.apply({ bar: 42 });
this.foo.bind({ bar: 42 })();
}
Expected output to the console is triple { bar: 42 }, since this value was changed for these calls.
However, VueComponent object is printed to the console.
I checked these methods for overloading, using
this.foo.bind === Function.prototype.bind // returns true,
they are not overloaded.
It may be caused by Vue using Proxy objects or even by templates compilation.
Simplest @vue/cli project with code above will be enough to reproduce the problem.
Thanks
this.foo({bar:42})is sufficient