鍍金池/ 問答/HTML/ 對 Jquery 的 Tigger 有點疑問

對 Jquery 的 Tigger 有點疑問

class Plugin {

  constructor(element, options) {
    this._setup(element, options);
    var pluginName = getPluginName(this);
    this.uuid = GetYoDigits(6, pluginName);

    if(!this.$element.attr(`data-${pluginName}`)){ this.$element.attr(`data-${pluginName}`, this.uuid); }
    if(!this.$element.data('zfPlugin')){ this.$element.data('zfPlugin', this); }
    /**
     * Fires when the plugin has initialized.
     * @event Plugin#init
     */
    this.$element.trigger(`init.zf.${pluginName}`);
  }

  destroy() {
    this._destroy();
    var pluginName = getPluginName(this);
    this.$element.removeAttr(`data-${pluginName}`).removeData('zfPlugin')
        /**
         * Fires when the plugin has been destroyed.
         * @event Plugin#destroyed
         */
        .trigger(`destroyed.zf.${pluginName}`);
    for(var prop in this){
      this[prop] = null;//clean up script to prep for garbage collection.
    }
  }
}

這段代碼里面的

this.$element.trigger(`init.zf.${pluginName}`);

不是很懂,代碼里面沒有聲明任何 "init.zf.xxx" 這類事件,那這個 trigger 觸發(fā)的是什么?

回答
編輯回答
不將就

The constructor should also call an _init() method, and if needed an _events() method, followed by a DOM event indicating that the plugin is done being initialized.

function Plugin(element, options) {
  // ...

  this._init();
  this._events();
  this.$element.trigger('init.zf.plugin');
}

看到官網(wǎng)的這個表述:followed by a DOM event indicating that the plugin is done being initialized,感覺很迷

2018年8月2日 00:29
編輯回答
擱淺

這個事件是提供給使用者使用的,不需要在這里聲明,比如element.on(”xxx”,function(){})

2017年4月24日 18:06