首页 > 其他 > 详细

$.extend()

时间:2018-01-24 12:03:10      阅读:210      评论:0      收藏:0      [点我收藏+]

1. 了解extend

 jQuery.extend( 
        { name: “John”, location: { city: “Boston” } }, 
        { last: “Resig”, location: { state: “MA” } } 
    ); 

    =》{ name: “John”, last: “Resig”, location: { state: “MA” } } 

更深入的extend:

jQuery.extend(

    true, 
    { name: “John”, location: { city: “Boston” } }, 
    { last: “Resig”, location: { state: “MA” } } 
); 

=》 { name: “John”, last: “Resig”,  location: { city: “Boston”, state: “MA” } } 

2. jQuery.extend(object) / $.extend(object)扩展了jQuery/$类本身.为类添加新的方法,如:

$.extend({ 
    add:function(a,b){return a+b;}, 
    minus:function(a,b){return a-b}, 
    multiply:function(a,b){return a*b;}, 
    divide:function(a,b){return Math.floor(a/b);} 
}); 

var sum = $.add(3,5)+$.minus(3,5)+$.multiply(3,5)+$.divide(5,7); 
console.log(sum); 

经过例子2可以看出extend可以扩展$,为其增加新的对象,方便我们使用(如:$.add(3,5))

 

$.extend()

原文:https://www.cnblogs.com/xjy20170907/p/8340840.html

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