Codepen: https://codepen.io/codingkiwi_/pen/XWMBRpW
Lets say you have a class:
class MyClass {
constructor(){
this.entries = ["a"];
//=== example change triggered from INSIDE the class ===
setTimeout(() => {
this.entries.push("c");
}, 1000);
}
}
And in a component you get an instance of that class:
const { reactive } = Vue;
const App = {
setup() {
const myobject = reactive(new MyClass());
//=== example change triggered from OUTSIDE the class ===
setTimeout(() => {
myobject.entries.push("b");
}, 500);
return {
myobject
};
}
}
The myobject.entries array in the DOM will display the entries "a"
and "b"
, but not "c"
this.listener = () => { this.entities.push(); }
(to be able to unsubscribe it later) and so, like you explained, "this" in the listener function referred to the original instance – Amoakuh