Is there a jQuery equivalent for event model / event publishing for YUI 2 subscription?

I learned how to develop in Javascript using the YUI 2 library, and wondered if there was a jQuery equivalent of custom events ( http://developer.yahoo.com/yui/event/#customevent )

In particular, I want to be able to define custom events without first connecting listeners.

In YUI, I will create a page class and declare different user events that you can subscribe to. Below is a sample code to demonstrate what I want to do, but using jQuery

function ListPage() {
    var me = this;
    this.initEvent = new YAHOO.util.CustomEvent("initEvent");

    this.init = function() {
         // initialize events, DOM, etc
         this.initEvent.fire(me);
    }
}

In a Javascript application, I would like to subscribe to initEvent.

var page = new ListPage();
page.initEvent.subscribe(
    function (type, args) {
        // do stuff here
    }
);

page.init();

Are there any tutorials / examples of something similar in jQuery?

, - bind() trigger(), , , bind().

jQuery , ?

, . !

+3

Source: https://habr.com/ru/post/1783965/


All Articles