YUI 3 學習筆記:event

來源:互聯網
上載者:User

event 模組包括 event, event-custom, event-simulate 三部分,類圖如下:

  1. Event 類的調用融合在 Node 中,和 Loader 與 YUI().use 的關係類似。
  2. 任何對象,只要擴充 EventTarget 介面,就自動具有了一套事件管理機制。使用很簡單:
    YUI().use('event', function(Y) {
    function Pig() {
    // 公布事件
    this.publish('farting', {
    emitFacade: true,
    defaultFn: function() {
    alert('豬豬放屁啦');
    }
    });
    }
    Pig.prototype.fart = function() {
    // 觸發事件
    this.fire('farting');
    };
    Y.augment(Pig, Y.EventTarget);

    var pig = new Pig();
    // 訂閱事件
    pig.on('farting', function(e) {
    e.preventDefault();
    alert('小豬豬乖,不放屁');
    });
    pig.fart();
    });
  3. CustomEvent 很完整的實現了一套事件管理機制,對象的冒泡、立即停止、訂閱器的先進先出和取消執行等等,YUI 3 都支援。
  4. Do 實現了一套簡單的 AOP 機制。
  5. DOMEventFacade 對原生 e 做了封裝,使用起來更自然,很舒服。
  6. Y.Env.evt.plugins 是事件處理的擴充鉤子。在 YUI 3 的代碼中,這種擴充和分離機制用得比較多。

快樂學習,歡迎討論。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.