JSFiddle - React, Tailwind, and code Playground

by demee

JavaScript

YUI({filter: 'raw', debug: true}).use('event', 'oop', function(Y){
    function MyObject() {
        MyObject.superclass.constructor.apply(this, arguments);
        // create a custom event.  it is not necessary to explicitly publish an event
        // unless you need to override the default configuration
        this.publish("myobject:event", {
            // configuration options for this event
        });
    }
    
    MyObject.NAME = "MyObject"; 
    MyObject.ATTRS = {}; 
    // augment the Publisher with EventTarget:
    Y.augment(MyObject, Y.EventTarget, null, null, {
        // this argument is provided to EventTarget's constructor, and
        // lets you set up default configuration values for every event
        // published on this event target.
    });
    
    Y.extend(MyObject, Y.Base, {
        run: function(){
            this.fire('myobject:event'); 
        }
    }); 
    
    var myobj = new MyObject(); 
    
    myobj.on('myobject:event', function(e){
        alert(arguments);
    });
    
    myobj.run()
    
});