$.extend

来源:互联网 发布:2g神优化单机游戏 编辑:程序博客网 时间:2024/05/22 02:29

1.$.extend(obj); 为jQuery类本身添加新的方法

2.$.fn.extend(ojb);给jQuery对象添加方法

$.exetend({

page:fun(){

}

})

$.page();

$.fn = $.prototype

$.fn.extend({

test:function(){

}

});

$("#test").test();

第二种就是为jQuery类添加成员函数。jQuery类的实例才可以电泳这个成员函数,$.extend()并不会把方法拓展到对象实力上,引用她的方法也需要通过$.page();实现;

我们可以拓展一个对象到jQuery prototype里去,这样的话就是插件机制了。

; (function ($ ){

$.fn.test = function(option){};

test = {

function(options){

};

}

$.fn.extend(test) = $.prototype.extend(test);

})(jQuery,window,document);


0 0
原创粉丝点击