繁体   English   中英

需要替代方法而不是 jQuery 插件中的 `arguments.callee`

[英]Need Alternate Approach Instead of `arguments.callee` in jQuery Plugin

随着 `arguments.callee 弃用,我想找到其他方法来扩展我创建的 jQuery 插件,以从外部执行其内置方法之一。

我的样本 jQuery 插件:

(function($) {
$.myPlugin = function(options) {
  // normal var and methods

  // this is to execute a method from outside
  arguments.callee.close = function() {
    // to do when this is called
  }
}
}(jQuery))

该插件将用于它的正常使用

$(selector).myPlugin();

这是触发插件内部的“close”方法

$(selector).myPlugin.close()

我找到了这个问题的答案并与大家分享:

(function($) {
  function myPlugin(options) {
    // normal var and methods: do whatever I want...

    myPlugin.close = myPlugin.close.bind(this);
  }

  myPlugin.close = function() {
    // do this thing
  }

  $.fn.myPlugin = myPlugin;

}(jQuery));

这允许我用这个调用 close 方法:

$(selector).myPlugin.close();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM