V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NickHopps
V2EX  ›  程序员

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

  •  
  •   NickHopps · 2018-05-22 13:06:59 +08:00 · 1098 次点击
    这是一个创建于 2138 天前的主题,其中的信息可能已经有所发展或是发生改变。

    首先是插件类

    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 有什么用?有特殊的作用吗?

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4993 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 09:38 · PVG 17:38 · LAX 02:38 · JFK 05:38
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.