您好,我刚开始接触 JQuery 插件,但我在理解命名空间时遇到了一些问题。
给定下面的示例,当我输入“提交”函数时,如何在提交函数中获取原型实例?像“var self = this;” 在其他功能?该方法中的 this 指的是表单元素。
(function ($, window, document, undefined) {
var PluginPrototype = {
init: function (options, element) {
var self = this;
$(element).find('form').submit(self.submit);
self.otherMethod();
},
submit: function(){
var self = this; // the form element
},
otherMethod: function () {
var self = this; // the prototype
},
}
$.fn.pluginname = function (options) {
return this.each(function () {
var plugin = Object.create(PluginPrototype);
plugin.init(options, this);
$.data(this, 'pluginname', comment);
// Get it by
// $.data($(select)[0], 'comment');
});
};
$.fn.pluginname.Settings = {
};
}(jQuery, window, document));