JSFiddle - React, Tailwind, and code Playground

by NibblyPig

HTML

<button id='clickMe'>Add alert</button>

<div id='myAlerts'>
</div>

JavaScript

// Alert Generator
function AlertGenerator () {
 
    this.AlertGeneratedEvent = [];
    
    this.doWarning = function doWarning()
    {
        $('#myAlerts').append('<div>Warning Occured!</div>');
        
        for (var i=0; i < this.AlertGeneratedEvent.length; i++)
        {
            this.AlertGeneratedEvent[i]();
        }
    }
}

// My generator
var myGenerator = new AlertGenerator();

// Page setup
$('#clickMe').click( function () { myGenerator.doWarning();  } );

// What I want when an event occurs
function warningAdded()
{
    alert('A new warning has been added.');
}

// Register for warnings
myGenerator.AlertGeneratedEvent.push(warningAdded);