question how are functions in: vue methods forced to bind to an vue instance?
var obj = {
eventHandle: function (){
// thiswindow
console.log(this);
}
};
window.addEventListener("resize", obj.eventHandle, false);
< hr >
var obj = {
eventHandle: function (){
// thiswindow
console.log(this);
}.bind(obj)
};
window.addEventListener("resize", obj.eventHandle, false);
< hr >
var vm = new Vue({
el: "-sharpapp",
methods: {
eventHandle: function (){
console.log(this);
}
},
mounted(){
/*
// thisvue
window.addEventListener("resize", this.eventHandle.bind(this), false);
*/
/* thisvuewindow
thisvue */
window.addEventListener("resize", this.eventHandle, false);
}
});