你好,我刚开始进入JQuery插件,但我有一些理解命名空间的问题。JQuery和原型命名空间
鉴于下面的例子,当我进入“提交”功能,我如何获得提交功能内的原型实例?像“var self = 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));
你在说什么“实例”? – Ohgodwhy 2013-05-13 17:35:56