get()和eq()方法的比较

一、get(num)方法  【返回(DOM)元素对象】
 
    1、源码如下:  //是对'(类)数组'下标访问方式的封装  可以使用[i]方法取得同样的效果  获得对当前元素的引用
  1.  get: function( num ) {
  2. //  this指针指向调用get的(Object)对象
  3. //  console.log(this);
  4. return num != null ?
  5. // Return just the one element from the set  //仅仅返回'堆栈'中的一个元素
  6. ( num < 0 ? this[ num + this.length ] : this[ num ] ) :   //负值则从右边开始算起  '堆栈'对象没有改变
  7. // Return all the elements in a clean array
  8.  slice.call( this );  //若没有参数则返回整个'堆栈'
  9.  }
    2、slice()源码如下:
  1. slice: function() {
  2.   return this.pushStack( slice.apply( this, arguments ) );
  3.  }
二、eq(i)方法  【返回jQuery对象】
 
    1、源码分析
  1.  eq: function( i ) {
  2.   var len = this.length,  //原'堆栈'的长度
  3.    j = +i + ( i < 0 ? len : 0 );  //允许负值
  4.   return this.pushStack( j >= 0 && j < len ? [ this[ j ] ] : [] );  //返回一个新的'堆栈'
  5.  }
    2、使用end()方法可以查看原'堆栈'的情况
 
三、看图 不解释(有图有真相)
 
posted @ 2016-05-20 13:19  DeadGhost  阅读(196)  评论(0编辑  收藏  举报