• 请不要在回答技术问题时复制粘贴 AI 生成的内容
NickHopps
V2EX  ›  程序员

对 Foundation 中的插件代码有点疑问,求前端大佬看看

  •  
  •   NickHopps · May 22, 2018 · 1921 views
    This topic created in 2952 days ago, the information mentioned may be changed or developed.

    首先是插件类

    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.
        }
      }
    }
    

    这段代码里面的 init.zf.${pluginName}destroyed.zf.${pluginName} 事件都找不到任何声明,在扩展的具体插件里面也没有声明这两个事件,请问这里的 trigger 有什么用?有特殊的作用吗?

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1007 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 18:06 · PVG 02:06 · LAX 11:06 · JFK 14:06
    ♥ Do have faith in what you're doing.