首页 > Web开发 > 详细

jQuery 的方法扩展,$.extend()、$.fn.extend()和$.fn区别

时间:2015-04-16 19:11:46      阅读:334      评论:0      收藏:0      [点我收藏+]

$.extend(object)

是在jQuery的 类 上扩展,如 $.ajax();

 

$.fn.extend(object)

是在jQuery的 实例 上扩展,也就是在 jQuery.prototype 上添加 成员函数, 如:

$.prototype.method = function(){};

 

$.fn 和 $.fn.extend(object) 都是添加 成员函数,是写法不一样

代码:

(function($){
    var fun = function(){
        return {
            aa: function(){
                console.log(1)
            }
        }
    };
    $.fn.extend(fun());
    $().aa();         //输出 1

    //覆盖了 aa()的函数
    $.fn.aa = function () {
        console.log(11);
    };
    $().aa();    //输出 11
})(jQuery);

 

$() 就是一个 jQuery 的实例;

参考:http://caibaojian.com/jquery-extend-and-jquery-fn-extend.html

jQuery 的方法扩展,$.extend()、$.fn.extend()和$.fn区别

原文:http://www.cnblogs.com/damade/p/4432757.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!