例子
`<body>
<div>div1</div>
<div>div2</div>
<div>div3</div>
<div>div4</div>
<div>div5</div>
<h1>h1</h1>
</body>
<script>
$(function(){
$('div').pushStack( $('h1') );
})
</script>`
`pushStack: function( elems ) {
// Build a new jQuery matched element set
console.log( elems );
var ret = jQuery.merge( this.constructor(), elems );
//merge: function( first, second )
// Add the old object onto the stack (as a reference)
ret.prevObject = this;
/*
1、首先先生成一个新的对象
2、把对象依次挂载到空对象上
3、然后返回挂载后的空对象
4、再把调用pushStack方法的对象挂载到空对象上
5、设置空对象的执行上下文为document
6、返回空对象
*/
ret.context = this.context;
// Return the newly-formed element set
//console.log( ret )
return ret;
}`
console.log( elems );的结果如下:
jQuery的pushStack()方法,传入的数组对象,怎么第一次是调用它的对象的数组?
elems不是应该总是[h1]对象吗?