views:

329

answers:

1

hi all,

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

A: 

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

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);
jonnyheadphones