views:

122

answers:

2

I'm having an issue where I have ended up with two functions named the same (jquery.fn.filter). one is from a 3rd party plugin, the other is from one of my plugins. Obviously I can rename the function in my plugin, but how would it be best to go about about writing plugins to avoid the possibility of this happening? is it possible to introduce some sort of namespacing like java/.net do?

A: 

I like your opinion about jQuery namespacing.

(http://docs.jquery.com/Using_jQuery_with_Other_Libraries) doesn't help if you had ANY functions under the samename.

Ta Coen
I don't know how this helps. My issue is that both jQuery plugins define a function inside Query.fn with the same name. jQuery.fn.filterCharacters = function(options){...}
Jeremy
A: 

The question here is not whether the jquery code can be namespaced - the conflict you describe happens in the "exported" interface of your jQuery plugin, the function name for the user. This has nothing to do with namespacing in a traditional sense.

As it is a strong part of jQuerys concept to use short, easy-to-remember function names on the collections, there is nothing that really could be done about this without sacrificing simplicity.

Having said that, a possible, but ugly solution would look like:

$("#selector").fns("my.name.space.company")("myargument");

This code would call an imaginary function fns that resolves the given string to a real function and returns this function. However, implementing this function as a plugin imposes the same problem...

Conclusion: no way out ;-)

Steffen Müller
As a last note: there is no advantage to use such a poll function above using function names of the same length like$("#selector").my_name_space_company("myargument");
Steffen Müller