JQuery_2.1.0_日记 5.2
            时间:2014-05-03 16:37:05  
            收藏:0  
            阅读:333
        
        
        $.方法
    合并两个数组或类数组,将第二个数组添加到第一个数组的末尾
(2)$.grep(elems, callback, invert)
    使用callback对elems进行过滤,如果invert设置为true.则返回保留callback返回值为false的元素数组,如果invert设置为false则返回callback返回值为true的元素数组.
     Test_Script
     var arr
 = [‘a‘ , ‘b‘ , ‘c‘ ]
   arr = $.grep(arr, function (){
      //arguments[0]为elem,arguments[1]为elem在数组 中的索引
      if (arguments[1]
 === 1) {
          return false ;
      } else {
         return true ;
      }
   }, true );
   alert(arr[0]); //‘b‘
(3)$.proxy(fn, context[,args1][,args2]....)
   为fn绑定上下文执行环境,返回代理后的对象
   Test_Script
   function a() {
       alert(arguments.length) //3
       alert( this .JQuery);  //11
   }
   var proxy
 = $.proxy(a, {JQuery: ‘11‘ }, ‘arg1‘ , ‘arg2‘ );
   proxy(‘args3‘);
   $.proxy源码
   proxy: function(
 fn, context ) {
               var tmp,
 args, proxy;
               //如果参数context为字符串时修正参数
               if ( typeof context
 === "string" ) {
                     tmp = fn[ context ];
                      //执行上下文第一个参数
                     context = fn;
                      //函数为第一个参数的名为第二个参数的属性值
                     fn = tmp;
              }
               // Quick check to determine if target is callable, in
 the spec
               // this throws a TypeError, but we will just return undefined.
               if (
 !jQuery.isFunction( fn ) ) {
                      return undefined ;
              }
               // Simulated bind
               //2个后的参数作为代理后对象的参数
              args = slice.call( arguments, 2 );
               //代理后的函数
               proxy = function()
 {
                      return fn.apply(
 context || this, args.concat( slice.call(
 arguments ) ) );
              };
               // Set the guid of unique handler to the same of original
 handler, so it can be removed
               //设置代理函数的唯一标示
               proxy.guid = fn.guid = fn.guid || jQuery.guid++;
               return proxy;
       },
            评论(0)