开发者

Preventing conflict between jquery prototype/plugin methods

开发者 https://www.devze.com 2022-12-15 08:56 出处:网络
Suppose i have a main js file on the website that contains some code as follows: $.fn.extend({ break: function(){

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消