jQuery:扩展插件问题 [英] jQuery: extend plugin question

查看:88
本文介绍了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);

效果很好-alert(web.var1)给我"foo".

works nice - alert(web.var1) is giving me "foo".

我的问题:是否可以通过仅包含另一个具有更多代码的.js来扩展此插件?例如.我可以要求web.var2

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

我以前使用原型函数,可以通过简单地添加另一个引用它的js-include来扩展"它.就像tWeb.prototype.newfunction = function()

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()

这怎么用jQuery完成?

how could this be done with jQuery?

thx

推荐答案

可能,但是我不确定这是一个好习惯.

It is possible, but I'm not sure it's a great practice.

但是,您可以执行以下操作:

However, you could do something this:

jQuery.fn.tWeb.prototype.newfunction = function();

从样式POV出发,最好在插件封闭内增强原型.

It might be better, from a stylistic POV, to enhance the prototype within the plugin closure.

(function ($) {
  $.fn.tWeb = function () 
  {
    var me = this;
    me.var1 = "foo";

    this.done = function()
    {
        return this;
    }
    return this.done();
  };

  $.fn.tWeb.prototype.newFunction = function() {};



})(jQuery);

这篇关于jQuery:扩展插件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆