1.jquery.extend
对jQuery对象的扩展
jQuery.extend({ a:function(){}, b:function(){} })
这样的写法其实和下面是一样的:
jQuery.a=function(){}; jQuery.b=function(){}
只是extend写法更清晰明了,借鉴了js中prototype的写法
function Person(){} Person.prototype.a=function(){} Person.prototype.b=function(){} 或者 function Animal(){} Animal.prototype={ constructor: ClassB, a:function(){}, b:function(){} }
2.jquery.fn.entend
对jQuery元素的扩展,只能用在jQuery元素上,可以理解为普通方法。定义插件时需要返回this,以支持jQuery的链式操作。
jQuery.fn.extend({ width_add:function(){ return $(this).css('width','100px') ; } })
$('#domid').width_add();
this绑定了domid元素。