JQuery_2.1.0_日記 5.2

來源:互聯網
上載者:User

標籤:jquery

$.方法
(1)$.merge(first, second)    合并兩個數組或類數組,將第二個數組添加到第一個數組的末尾
(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;       },

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.