[jQuery] Re: Plugin's method called chained with selector or not?
Hi Juan, You probably shouldn't be making direct calls to a $.fn.methodName() function. I'm not sure what it is you want to accomplish, but perhaps a good example would be the each function. There is a $.fn.each which is called when you use $('.foo').each(). And there is a separate $.each that is meant to be called directly. In fact, $.fn.each calls $.each to do the iteration. Maybe you could use a pattern like that: Define a jQuery.methodName function for direct calls, and a jQuery.fn.methodName for calls via a jQuery object - which can use jQuery.methodName as a support function if that makes sense. -Mike _ From: Juan G. Hurtado Hi everyone, I am writing little plugins for helping me in my developments. Everything's ok, and easy to do, but now I'm face to face with a little problem. I've a plugin's method like this: [CODE] jQuery.fn.methodName = function(options) { // Code } [END CODE] The problem is that I want to know when I call the function this way: [CODE] $('elemento.class').methodName(); [END CODE] And when I call it this other way: [CODE] $.fn.methodName(); [END CODE] I need this in order to do the this.each thing inside the plugin's method. Hope everything is well explained, and sorry about my poor english. Thanks in advance. -- Juan G. Hurtado [EMAIL PROTECTED]
[jQuery] Re: Plugin's method called chained with selector or not?
Hi Michael, El 01/08/2007, a las 10:26, Michael Geary escribió: You probably shouldn't be making direct calls to a $.fn.methodName () function. I'm not sure what it is you want to accomplish, but perhaps a good example would be the each function. There is a $.fn.each which is called when you use $('.foo').each(). And there is a separate $.each that is meant to be called directly. In fact, $.fn.each calls $.each to do the iteration. Maybe you could use a pattern like that: Define a jQuery.methodName function for direct calls, and a jQuery.fn.methodName for calls via a jQuery object - which can use jQuery.methodName as a support function if that makes sense. I am writing little plugins for helping me in my developments. Everything's ok, and easy to do, but now I'm face to face with a little problem. I've a plugin's method like this: [CODE] jQuery.fn.methodName = function(options) { // Code } [END CODE] The problem is that I want to know when I call the function this way: [CODE] $('elemento.class').methodName(); [END CODE] And when I call it this other way: [CODE] $.fn.methodName(); [END CODE] I need this in order to do the this.each thing inside the plugin's method. First of all, thank you very much for your answer, it really make sense. I'm gonna test it right now, because it really seems to be the obvious way to do it. Thanks again. -- Juan G. Hurtado [EMAIL PROTECTED]