JSFiddle - React, Tailwind, and code Playground

by gevaraweb

JavaScript

addEvent = function () {

	this.userEventFirst = function () {};
	this.userEventTwo = function () {};

	this.attachEvent = function (event, handler) {

		switch ( event ) {
			case 'eventFirst':  this.userEventFirst = handler;	break;
			case 'eventTwo': 	this.userEventTwo = handler;	break;		
			break;
		}

	};

	this.working = function () {
		
		this.userEventFirst();	
		
		//... hard work
		console.log('working');
		
		this.userEventTwo();
	}	
	
};


// user - programmer


addEvent1 = new addEvent();

addEvent1.attachEvent('eventFirst', function() {

    console.log('click eventFirst');

});

addEvent1.attachEvent('eventTwo', function() {

    console.log('click eventTwo');

});

addEvent1.working();