例子的详细讲解

Filter Resolve

上面的的代码是怎么运行的呢

点击button的先执行 $.Deferred(),得到具有很多方法的defer

defer.resolve( 5 );

var doneList = jQuery.Callbacks( "once memory" ),
failList = jQuery.Callbacks( "once memory" ),
progressList = jQuery.Callbacks( "memory" ),
state = "pending";
lists = {
resolve: doneList,
reject: failList,
notify: progressList
}
for ( key in lists ) {
deferred[ key ] = lists[ key ].fire;
deferred[ key + "With" ] = lists[ key ].fireWith;
}
//根据上面的代码可得
//deferred[ 'resolve']=lists[ 'resolve'].fire;
//deferred[ 'resolveWidth']=lists[ 'resolve'].fireWith;
//deferred[ 'reject']=lists[ 'reject'].fire;
//deferred[ 'rejectWidth']=lists[ 'reject'].fireWith;
//deferred[ 'notify']=lists[ 'notify'].fire;
//deferred[ 'notifyWidth']=lists[ 'notify'].fireWith;
//因此resolve( 5 )执行了
fire: function() {
self.fireWith( this, arguments );
return this;
},
fireWith: function( context, args ) {
//stack=[];为true;firing 为false;flag={}
if ( stack ) {
if ( firing ) {
if ( !flags.once ) {
stack.push( [ context, args ] );
}
//memory =undefined
} else if ( !( flags.once && memory ) ) {
fire( context, args );
}
}
return this;
}
fire = function( context, args ) {
args = args || [];
//memory = [ context, args ];即为self,和5
memory = !flags.memory || [ context, args ];
fired = true;
firing = true;
firingIndex = firingStart || 0;
firingStart = 0;
firingLength = list.length;
for ( ; list && firingIndex < firingLength; firingIndex++ ) {
//函数执行后为false并且flags.stopOnFalse 为true时memory = true;
//注意这里执行了函数
if ( list[ firingIndex ].apply( context, args ) === false && flags.stopOnFalse ) {
memory = true; // Mark as halted
break;
}
}
firing = false;
if ( list ) {
if ( !flags.once ) {
if ( stack && stack.length ) {
memory = stack.shift();
self.fireWith( memory[ 0 ], memory[ 1 ] );
}
} else if ( memory === true ) {
self.disable();
} else {
//最终又把list函数组给赋值为空
list = [];
}
}
}

jquery1.7.2的源码分析(三)$.Deferred的更多相关文章

  1. jquery1.7.2的源码分析(一)

    说到jquery可能是大家最经常用到的,在日常的编写程序中最经常使用到,在使用jquery插件的同时,深入的解读jquery源码有利于我们学到设计的思想和实现的技巧 在jquery源码的分析中,其中艾 ...

  2. cocos2dx骨骼动画Armature源码分析(三)

    代码目录结构 cocos2dx里骨骼动画代码在cocos -> editor-support -> cocostudio文件夹中,win下通过筛选器,文件结构如下.(mac下没有分,是整个 ...

  3. spark[源码]-任务调度源码分析[三]

    前言 在上一篇文章中,我主要是讲解了DAG阶段的处理,spark是如何将一个job根据宽窄依赖划分出多个stage的,在最后一步中是将生成的TaskSet提交给了TaskSchedulerInmpl的 ...

  4. HashMap源码分析三

      HashMap的源码,在jdk1.5中相比jdk1.4,改动不大,有几个方面   1 jdk1.5中引入了范型,在HashMap中也有体现 2 引入了另一个hash值的计算方式,不过默认是关闭状态 ...

  5. Qt update刷新之源码分析(三)

    大家好,我是IT文艺男,来自一线大厂的一线程序员 上次视频给大家从源码层面剖析了Qt刷新事件(QEvent::UpdateRequest)的处理流程,这次视频主要从源码层面剖析对刷新事件的进一步处理, ...

  6. YII 的源码分析(三)

    前面已经看完了启动一个yii程序所要经过的流程,以及渲染一个页面是怎么完成的.今天要分析的是yii是如何处理用户请求的.也就是控制和动作部分. 还是以helloworld为例演示这一过程.我们在地址栏 ...

  7. Nop源码分析三

    程序的初始化工作和Ioc工作已经做完,nop默认引擎已经初始化. 下面在回到global文件的启动方法Application_Start()中, 1,继续分析下面的代码: var dependency ...

  8. java动态代理——字段和方法字节码的基础结构及Proxy源码分析三

    前文地址:https://www.cnblogs.com/tera/p/13280547.html 本系列文章主要是博主在学习spring aop的过程中了解到其使用了java动态代理,本着究根问底的 ...

  9. jquery1.7.2的源码分析(四)$.Deferred(2)

    jQuery.Callbacks = function( flags ) { // Convert flags from String-formatted to Object-formatted // ...

随机推荐

  1. Mac OS X中bogon的处理

    起因 最近写一个项目,之前在eclipse里的tomcat启动是没问题的,最近不知怎么了,启动的时候ehcache会报一个错误,说java.net.UnknownHostException: bogo ...

  2. 【译】Spring 4 @PropertySource和@Value注解示例

    前言 译文链接:http://websystique.com/spring/spring-propertysource-value-annotations-example/ 本篇文章将展示如何通过@P ...

  3. SQL:执行顺序

    SELECT语句的执行的逻辑查询处理步骤: (8)SELECT (9)DISTINCT(11)<TOP_specification> <select_list>(1)FROM ...

  4. Oracle数据库的 增、删、改、查

    有时候数据库的查询语句一时想不起来,或不确定是不是语句写的正确,现在整理了一下标准的基本查询语句,便于以后牢记: .数据操作语言 DML:添加(insert into).修改(update   set ...

  5. Linux shell脚本编程(一)

    Linux shell脚本编程: 守护进程,服务进程:启动?开机时自动启动: 交互式进程:shell应用程序 广义:GUI,CLI GUI: CLI: 词法分析:命令,选项,参数 内建命令: 外部命令 ...

  6. Ubuntu 一直掉线 以及连不上网 解决办法

    新装了一个Ubuntu 系统16.04才使用的时候一切顺利 但是过了两三天  就会出现 频繁掉线的情况 于是上网找大神们的解决办法 把文件 /etc/ppp/options 里面的一个数值改大一点 l ...

  7. plain framework 商业版 开发总结1 updated

    每天对着不同的计划,多多少少有一种无形的压力.特别是对技术不好的我来说,过程中遇到的问题实在不少,时常纠结良久.时间慢慢流逝,最后虽然感觉有些不足,但是也不至于差强人意.商业版的PF核心已经升级到1. ...

  8. BZOJ 1212: [HNOI2004]L语言 [AC自动机 DP]

    1212: [HNOI2004]L语言 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1367  Solved: 598[Submit][Status ...

  9. Spring 通知(Advice)和顾问(Advisor)

    AOP ( Aspect  Oriented Programming  面向切面编程)  在软件业,AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译 ...

  10. [LeetCode] Pow(x, n) 求x的n次方

    Implement pow(x, n). 这道题让我们求x的n次方,如果我们只是简单的用个for循环让x乘以自己n次的话,未免也把LeetCode上的想的太简单了,一句话形容图样图森破啊.OJ因超时无 ...