JSFiddle - React, Tailwind, and code Playground
HTML
<p id="B">
Hello
</p>
JavaScript
class A {
constructor(b) {
this.b = b;
}
setTimer(interval) {
setTimeout(this.b.tick, interval);
}
}
class B {
constructor(name){
this.name = name;
this.ele = window.document.getElementById('B');
}
tick() {
console.log(this);
this.ele.innerText += ' ' + this.name;
}
}
var a = new A(new B("World"));
a.setTimer(1);