Stephan Beal wrote:
On Jul 22, 11:57 pm, Klaus Hartl <[EMAIL PROTECTED]> wrote:
IMHO it is bad practice to store that element in the self, i.e. jQuery,
object.
...
A simple var should be sufficient.

jQuery.fn.myPlugin = function(targetField) {
     var textfield = jQuery(targetField);
     ...

};

Assuming we need to hold on to the target long-term (e.g., in inner
functions or even classes), would this be a more acceptable approach
to using self to sort the jQuery object:

jQuery.fn.myPlugin = function(targetField) {
    var self = this;
    self.target = targetField;
...
    var textfield = jQuery(self.target);
      ...
};

?

The difference is that this one is holding the selector string, and
not the jQuery object (unless, of course, the user passes a jQ as
targetField).

But that doesn't make any difference. It would still overwrite a property named "target" of the jQuery object.

You have to know jQuery very well to not accidently use a name that isn't already in use. And who knows if jQuery 1.1.4 does not introduce a target property on the jQuery object? Jörn described that very well a while ago in another thread - I think that was related to one of your plugins ;-)

Again, a var should be sufficient using closures. Or if you need to store things in another object, create a new one but do not use the jQuery object.


--Klaus

Reply via email to