views:

91

answers:

1

Suppose i have a main js file on the website that contains some code as follows:

$.fn.extend({
  break: function(){
    //code here
  },
  cut: function(){
   //code here
  },
  // ...many other methods
});

and i use it like so:

$('#mydiv').break().animate() ...

Now if i add an external jquery plugin file that also has a 'break' method, how do i prevent conflict between my $.fn methods and someone else's?

+3  A: 

You can't.

This is why many plugins, such as jQuery UI, only add a single method to the prototype which takes an action name as a parameter.

SLaks
Just came accross this: http://stackoverflow.com/questions/1537848/jquery-plugin-namespace I havent tried this yet but is it close to what i am looking for? Will it work if i place 'break' and 'cut' methods within '$.fn.myNamespace' ?
fenderplayer
Yes, that will also work. However, I've never seen a real plugin that does that.
SLaks