JQuery: plugin extension question

I have 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); 

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

my question is: is it possible to extend this plugin by simply including another .js that has more code? eg. what can i ask for web.var2

i previously used the prototype function and could โ€œextendโ€ it by simply adding another js-include that referred to it, for example. like tWeb.prototype.newfunction = function()

how can this be done using jQuery?

THX

+1
jquery plugins extend
Dec 11 '09 at 1:52
source share
1 answer

Maybe, but I'm not sure this is a great practice.

However, you can do something like the following:

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

Perhaps it would be better, with the help of stylistic POV, to improve the prototype in closing the plugin.

 (function ($) { $.fn.tWeb = function () { var me = this; me.var1 = "foo"; this.done = function() { return this; } return this.done(); }; $.fn.tWeb.prototype.newFunction = function() {}; })(jQuery); 
0
Dec 11 '09 at 2:00
source share



All Articles