jQuery:扩展插件问题
我有这个简单的插件代码:
(function ($) {
$.fn.tWeb = function ()
{
var me = this;
me.var1 = "foo";
this.done = function()
{
return this;
}
return this.done();
};
})(jQuery);
var web = new jQuery.fn.tWeb();
alert(web.var1);
工作得很好 -alert(web.var1) 给了我“foo”。
我的问题:是否可以通过简单地包含另一个具有更多代码的 .js 来扩展此插件?例如。我可以要求 web.var2
我以前使用过一个原型函数,并且可以通过简单地添加另一个引用它的 js-include 来“扩展”它,例如。就像 tWeb.prototype.newfunction = function() 一样,
这如何用 jQuery 来完成?
谢谢
i'm having this simple plugin code:
(function ($) {
$.fn.tWeb = function ()
{
var me = this;
me.var1 = "foo";
this.done = function()
{
return this;
}
return this.done();
};
})(jQuery);
var web = new jQuery.fn.tWeb();
alert(web.var1);
works nice - alert(web.var1) is giving me "foo".
my question: would it be possible extending this plugin by simply including another .js which has more code? eg. that i could ask for web.var2
i previously used a prototype function and could "extend" it by simply adding another js-include which refered to it eg. like tWeb.prototype.newfunction = function()
how could this be done with jQuery?
thx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(1)
这是可能的,但我不确定这是一个很好的做法。
但是,您可以这样做:
从风格 POV 出发,增强插件闭包中的原型可能会更好。
It is possible, but I'm not sure it's a great practice.
However, you could do something this:
It might be better, from a stylistic POV, to enhance the prototype within the plugin closure.