JSFiddle - React, Tailwind, and code Playground
HTML
<div id="output"></div>
JavaScript
var HelloWorldClass = function () {
var greetings = [];
this.greetings = greetings;
this.addGreeting = function (greeting) {
greetings.push(greeting);
};
this.sayHello = function () {
document.getElementById('output').innerHTML += this.greetings;
greetings.forEach(function (greeting) {
greeting.execute();
});
};
};
var TestClass = function () {
this.testHello = function (callback) {
alert("TestHello is working, now callback");
callback();
};
};
var main = function () {
var helloWorld = new HelloWorldClass();
var test = new TestClass();
helloWorld.addGreeting({
execute: function () {
alert("Konichiwa!");
}
});
helloWorld.sayHello();
test.testHello(helloWorld.sayHello);
}
main();