Hi, I have a little plugin factory script, based on some code from others.. I think it'll get you where you're trying to go:
http://code.paulirish.com/sandbox/pluginfactory.js You can define those functions in an object literal (or in a constructor), and then reference the element with this.$elem. G'luck. On Nov 26, 3:25 am, Lukáš <lukash...@gmail.com> wrote: > Nevermind that, I figured it out, as always I didnt think of the > simplest option. > > But I will reform my question to this. > > I create my own function. > > $.fn.dr = > function(settings) { > this.each(function(settings) { > process(this, settings); > }); > > return this; > > } > > And now I want to extend my own function as follow: > > $.extend($.fn.dr, { > update: > function(input) { > process(this, false, 'update', input); > }, > del: > function(input) { > > }, > add: > function(input) { > > } > }); > > My problem is that I cant access "this", which is the current jQuery > object. so "this.each..." wont work and I have no idea how to access > the current object there, cry. > > Anyway the "process" function will create new "datareader" object and > loop trough all attributes of the provided element from selector and > find the first reference of the bracket (provided in settings) and > then create and return an object of the data provided. As I said that > works with no problem. > > But how can I access the jQuery object in extended functions? > Accessing it when I will extend jQuery its easy, but I dont understand > how to do it when I extend my own function instead of jQuery. > > I hope you guys get it now ;P > > Regards > > On 25. Nov, 16:19 h., "\"Cowboy\" Ben Alman" <cow...@rj3.net> wrote: > > > I'd love to help, but I have absolutely no idea what you're trying to > > do! I'd recommend starting with working code, then figure out how to > > organize and generalize it. > > > - Ben > > > On Nov 25, 4:04 am, Lukáš <lukash...@gmail.com> wrote: > > > > Hey, > > > > so after some time I decided to look into plugin creation. Since for > > > some time I was forced to load up to 30 different variables from > > > inputs, so I created a function that would read all the data from one > > > instead of multiple inputs. So now I tried to reform it into a plugin. > > > The problem starts here. > > > > Here is the code (simplified). > > > > (function($) { > > > $.datareader = function(settings) { > > > if(!settings) { > > > this.settings = $.extend({}, > > > $.datareader.defaults, settings); > > > } else this.settings = settings; > > > }; > > > > $.datareader.defaults = { > > > bracket: '{}' > > > } > > > > $.extend($.fn.dr, { > > > update: > > > function(input) { > > > process(this, false, 'update', input); > > > }, > > > del: > > > function(input) { > > > > }, > > > add: > > > function(input) { > > > > } > > > }); > > > > $.fn.dr = function(settings) { > > > this.each(function(settings) { > > > process(this, settings); > > > }); > > > > return this; > > > } > > > > })(jQuery); > > > > "process" function in does all the stuff needed since I need it > > > multiple times and returns an object. Now my question is about > > > "$.fn.dr". How can I force it to return a value instead of just > > > executing the function, I tried multiple ways but none of them worked. > > > Which would be fine for the functions that extend this one, since > > > there I need it to be executed instead of returing a value. Also I > > > dont really need the "$.fn.dr" function to loop trough all elements > > > since its only for my internal use, I know it will be fired only on > > > one. > > > > So to put it simple how can I force the function to return an actual > > > value? :) > > > > Oh and one more think. I create a "new $.datareader" object each time > > > its fired. Wouldnt that be a major slowdown or something if it will be > > > exucuted lets say 20 times? (which can easily happen) -- You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-...@googlegroups.com. To unsubscribe from this group, send email to jquery-dev+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en.