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?
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.
精彩评论