牧羊人nacy
2019-03-15 14:10:34
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ā)的是什么?
2 回答

呼喚遠(yuǎn)方
TA貢獻1856條經(jīng)驗 獲得超11個贊
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,感覺很迷
添加回答
舉報
0/150
提交
取消