$.extend:
1,$.extend(object):扩展jQuery类方法,jQuery是一个类,相当于给这个类添加静态方法,添加的静态方法是能被jQuery这个类调用,实例不能继承使用。
$.extend({ fun1:function(){ alert('this is fun1'); }, fun2:function(){ alert('this is fun2'); } });
$.fun1();
$.fun2();
2,$.extend(target,object1[,object2,objectN]):扩展目标对象,返回值 是被扩展后的目标对象
var targetObj = {name:'lili', age: 13}; var object1 = {name:object1,sex:'女'}; var object2 = {name:'object2',favorite:'苹果'}; $.extend(targetObj, object1,object2);
返回结果:{name: "object2", age: 13, sex: "女", favorite: "苹果"}
$.fn.extend:
$.fn = $.prototype = jquery.prototype;相当于给jQuery类添加'成员方法',实例也可以调用扩展的方法
$.fn.extend({ alertEventType:function(){ // $(this).click(function(e){ // console.log(e.type); // }) $(this).on('click',function(e){ console.log(e.type); }) } }); $('#prototype').alertEventType();