jQuery源码分析-----pushStack
来源:互联网 发布:远程数据采集器 编辑:程序博客网 时间:2024/06/05 04:29
pushStack是jQuery底层方法
pushStack方法虽然在高层不会用到,但很多方法都会调用它
举例:
html结构为ul下5个li
var li = $('li');var s = li.slice(2);var end = s.end();pushStack:// Take an array of elements and push it onto the stack// (returning the new matched element set)pushStack: function( elems ) { // Build a new jQuery matched element set var ret = jQuery.merge( this.constructor(), elems ); // Add the old object onto the stack (as a reference) ret.prevObject = this; ret.context = this.context; // Return the newly-formed element set return ret;}slice: function() { var temp = slice.apply( this, arguments ); return this.pushStack( temp );}
- 当执行
li.slice(2)
时,进入slice
方法,this
指的是li,temp
为后3个li
,返回this.pushStack
,进入pushStack
方法,参数为temp
,首先将temp
封装成jQuery
对象并赋值给ret
,即待返回的对象,将this
赋值给ret
的prevObject
属性(方便后续调用end
方法),返回ret
。此时ret
的结构包括
{ jQuery:temp prevObject:li context:document}
- 当执行
s.end()
时:
end: function() { return this.prevObject || this.constructor(null);},
返回s
的prevObject
,即li
阅读全文
0 0
- jQuery源码分析-----pushStack
- jQuery原型方法.pushStack源码分析
- jQuery-源码阅读,pushStack()入栈方法
- jQuery中的pushStack
- jQuery.pushStack的深入讲解
- jQuery对象的入栈pushStack()
- [ jQuery ] jQuery 源码分析!
- Jquery源码分析(一)
- jQuery 源码分析
- JQuery 源码分析 -1
- jQuery源码分析
- jquery源码分析
- Jquery queue源码分析
- jQuery源码分析
- Jquery源码 基础分析
- jquery源码分析
- jQuery 源码分析
- jQuery源码分析
- @property和@synthesize
- ZMQ(java)-编译的心酸历程
- 事物注解方式: @Transactional
- AttributeError: 'module' object has no attribute 'text_format'
- 面经
- jQuery源码分析-----pushStack
- LeetCode-string-Longest Substring Without Repeating Characters
- linux centos FTP服务器搭建vsftpd配置
- Android实现透明状态栏方法以及改变状态栏文字颜色
- 关于使用Maven管理引入Oracle驱动报错
- 关于android 消息提醒,在网上找到这个项目在eslipse中使用ValueAnimator报错
- 文章标题
- heap和stack的不同
- zookeeper分布式原理实战解析