- 浏览: 184450 次
-
最新评论
-
adamed:
zhangwenzhuo 写道为什么this.get()会返回 ...
jQuery源码历代记5 -
zhangwenzhuo:
为什么this.get()会返回本身的呢?
jQuery源码历代记5 -
narutolby:
支持下~,哈哈~
jQuery历代记1 -
cpszy:
mark下
jQuery历代记1 -
gleams:
支持你
jQuery历代记1
ExtJS老大在官方论坛的一个回复,转到这里收藏下
The split onRender/render and their siblings are the result of a deep inheritance chain and a desire to not duplicate code. They are based on a common OO design pattern called Template Method.
The control structure (inversion of control) that is the result of the application of a template pattern is often referred to as the Hollywood Principle: "Don't call us, we'll call you." Using this principle, the template method in a parent class controls the overall process by calling subclass methods as required.
Let's me paint a simple picture.
Now looking at this code, it seems very straight forward and it can't fail right? However, what happens when you add a subclass?
Look at the result of the 2 options:
Option 1 has a few problems.
a) There's no way to know if the event was cancelled, so you can't stop the manager logic. You could return false if it is cancelled but then you have different return types and the API suffers.
b) The most serious issue is the "quit" event gets fired prematurely. While in this example that might be a problem, but in a Component that involves rendering and you need to know that the component is fully rendered, it would be a major issue.
Option 2 has a few problems as well:
a) The beforequit event no longer fires in advance and can no longer allow for cancellation of the action. This is a major problem.
b) The manager logic has to come first - this is a major problem especially when rendering a component and your based class is probably rendering something the subclass needs (e.g. this.el!)
Using a Template Method, we can solve this problem easily:
So not only does this solve the problem described above easily, it also means all subclasses no longer have to worry about wrapping things in events since the base class will handle that automatically.
Another even more important benefit of "Template Method" that is not present in this simple example but that is used in Component rendering is that then you can have a defined execution flow in a base class and you know all subclasses will be complete with what they need to do at each step before continuing to the next step.
Regards,
Jack
The split onRender/render and their siblings are the result of a deep inheritance chain and a desire to not duplicate code. They are based on a common OO design pattern called Template Method.
引用
Quote:
The template method is used to:
* let subclasses implement behaviour that can vary
* avoid duplication in the code: you look for the general code in the algorithm, and implement the variants in the subclasses
* to control at what point(s) subclassing is allowed.
The template method is used to:
* let subclasses implement behaviour that can vary
* avoid duplication in the code: you look for the general code in the algorithm, and implement the variants in the subclasses
* to control at what point(s) subclassing is allowed.
The control structure (inversion of control) that is the result of the application of a template pattern is often referred to as the Hollywood Principle: "Don't call us, we'll call you." Using this principle, the template method in a parent class controls the overall process by calling subclass methods as required.
Let's me paint a simple picture.
var Employee = function(){ .... this.addEvents({ beforequit: true, quit: true }); } Ext.extend(Employee, Ext.util.Observable, { quit : function(){ if(this.fireEvent('beforequit', this) !== false){ // "important logic" that must run when // when an employee quits this.fireEvent('quit', this); } return this; } }
Now looking at this code, it seems very straight forward and it can't fail right? However, what happens when you add a subclass?
var Manager = Ext.extend(Employee, { quit : function(){ // Option 1 is to call the base class first Manager.superclass.quit.call(this); // then do custom Manager quit logic ... Manager logic ... // Option 2 is to do the Manager specific logic first ... Manager logic ... // and then call the base class Manager.superclass.quit.call(this); return this; } });
Look at the result of the 2 options:
Option 1 has a few problems.
a) There's no way to know if the event was cancelled, so you can't stop the manager logic. You could return false if it is cancelled but then you have different return types and the API suffers.
b) The most serious issue is the "quit" event gets fired prematurely. While in this example that might be a problem, but in a Component that involves rendering and you need to know that the component is fully rendered, it would be a major issue.
Option 2 has a few problems as well:
a) The beforequit event no longer fires in advance and can no longer allow for cancellation of the action. This is a major problem.
b) The manager logic has to come first - this is a major problem especially when rendering a component and your based class is probably rendering something the subclass needs (e.g. this.el!)
Using a Template Method, we can solve this problem easily:
var Employee = function(){ .... this.addEvents({ beforequit: true, quit: true }); } Ext.extend(Employee, Ext.util.Observable, { quit : function(){ if(this.fireEvent('beforequit', this) !== false){ this.onQuit(); this.fireEvent('quit', this); } return this; }, onQuit : function(){ // "important logic" that must run when // when an employee quits } } var Manager = Ext.extend(Employee, { onQuit : function(){ Manager.superclass.onQuit.call(this); .. Manager logic ... } });
So not only does this solve the problem described above easily, it also means all subclasses no longer have to worry about wrapping things in events since the base class will handle that automatically.
Another even more important benefit of "Template Method" that is not present in this simple example but that is used in Component rendering is that then you can have a defined execution flow in a base class and you know all subclasses will be complete with what they need to do at each step before continuing to the next step.
Regards,
Jack
发表评论
-
jQuery Mobile插件开发1
2012-10-17 14:31 3646最近的项目使用jQuery Mobile开发别克手机官网 ... -
localStorage、sessionStorage用法总结
2012-10-15 17:25 88630localStorage和sessionStorage ... -
Bit This 视觉差滚动效果分析
2012-07-06 11:44 2902Bit This 是一家位于西班牙马德里的代理公司。 ... -
深入详解EXT2.3事件增加及删除源码
2012-02-23 11:06 1571先看addListener也就是Ext里面的on方法 ... -
答复: [原创]ExtJS 2.3源码分析(2012年02月21日更新)
2012-02-21 13:51 998临时详解下下面的代 ... -
JAVA验证中文正则
2012-02-20 22:03 1244public static void main(String[ ... -
HTML5 Geolocation小结
2012-02-20 17:23 1241HTML5中 Geolocation主要包 ... -
HTML5中JSON的原生支持
2012-02-20 17:22 10651、可以直接使用JSON.stringify(jsonobje ... -
JavaScript函数变换
2012-02-20 17:16 980在编写JS框架时有时会遇到编写的方法涉及复杂的操作或需要定义特 ... -
如何在MyEclipse中修改Maven本地仓库位置
2010-06-17 23:14 84611、本地需要安装Maven。这里假设安装在D:\Program ... -
目前已出版的基本Flex4书籍(是英文已出版)
2010-04-01 13:40 24351、Professional BlazeDS: Creatin ... -
JavaScript系列视频
2010-03-24 11:18 943大家好,由我和CSDN的学生大本营合作进行JavaScript ... -
Flex4正式版命名空间的变化
2010-03-24 11:03 1364与之前的FLEX3相比,在FLEX4的beta版(包括beta ... -
如何使用ExtJS构建应用系统3
2009-12-30 16:14 1398原文地址:http://blog.extjs.eu/know- ... -
如何使用ExtJS构建应用系统2
2009-12-30 16:13 2124原文地址:http://blog.extjs.eu/know- ... -
如何使用ExtJS构建应用系统
2009-12-30 16:10 3041原文地址:http://blog.extjs.eu/know- ... -
《数据仓库生命周期工具箱》读书笔记 1
2009-11-05 13:39 1205今天读的是这本书的第6 ... -
《数据仓库》读书笔记 4
2009-10-26 17:55 916今天开始读数据仓库的第四章,这一章讲解的是数据仓库中的粒度。 ... -
《数据仓库》读书笔记 3
2009-10-16 15:07 982这两天读了《数据仓库》第三章,这一章讲解的是设计数据仓库。 ... -
《数据仓库》读书笔记 2
2009-10-15 10:12 933读了数据仓库第2章,这 ...
相关推荐
在本文中,我们将深入探讨如何在ExtJS4中利用Ajax数据源来绘制线形图表(Line chart)。ExtJS是一个强大的JavaScript库,专为构建富客户端应用程序而设计,它提供了丰富的图表组件,使得数据可视化变得简单易行。让...
通过以上方法,开发者可以有效地自定义ExtJS中的工具栏和菜单样式,从而提升应用程序的用户体验和视觉效果。此外,还可以进一步探索其他组件如树形菜单、表格和按钮等的样式修改方法,使整个应用界面更加一致和美观...
1. **ExtJS实用开发指南**:此部分主要针对ExtJS的实际应用,包含如何快速上手、组件的使用、布局管理、数据绑定和Ajax交互等内容。开发者可以从中了解到如何创建基本的页面结构,使用GridPanel展示数据,以及通过...
在"ExtJs3.3中文API.CHM"中,开发者可以找到关于ExtJS 3.3的所有API和类的详细描述,以及相关的示例代码。 ExtJS 3.3的核心特性包括: 1. **组件化**:ExtJS基于组件模型,提供了一系列预定义的UI组件,如按钮、...
这份“extjs中文帮助文档和英文api”提供了全面的ExtJS API信息,帮助开发者理解并有效地使用这个框架。 中文帮助文档(extjs帮助文档.chm)对ExtJS的各种组件、类、方法、属性进行了详尽的解释,使得不懂英文或者...
Extjs中文文档,包含Extjs的基本语法和各个类的详细说明以及用法。
Extjs 中文API文档,有对Extjs相关API的中文说明
表格控件是ExtJS中极为重要的一部分,提供了大量的特性来增强用户体验和功能性。 **核心功能**: - **基本功能**:支持单选或多选行、高亮显示选中行、列宽调整、按列排序等。 - **高级功能**:自动生成行号、全选...
**ExtJs**是一款基于JavaScript的企业级Web应用开发框架,它提供了丰富的UI组件和强大的功能,帮助开发者快速构建高性能的Web应用程序。本文档旨在引导初学者快速入门ExtJs,通过实例演示如何搭建开发环境并实现简单...
在《ExtJs 实例》中,你将找到各种实际应用场景的代码示例,这些实例涵盖了ExtJs的各种组件和功能。通过学习这些实例,你可以更好地理解如何在实际项目中应用ExtJs,例如如何创建网格(Grid)、表单(Form)、树形...
手册中涵盖了ExtJS 3.3的所有类、方法、事件、属性和配置选项,对于开发者来说是不可或缺的工具。 1. **组件系统**:ExtJS的核心在于其组件模型,包括窗口(Window)、面板(Panel)、表格(Grid)、表单(Form)等...
- **命名空间**: 命名空间在Extjs中用于组织和管理代码,避免变量和函数名的冲突。 #### 3. Extjs OOP Extjs支持面向对象编程,其对象模型包括: - 类的定义(Ext.extend) - 对象实例化(通过new关键字) - 原型...
ExtJS3 升级到 ExtJS4 方案 ExtJS3 升级到 ExtJS4 需要修改大量代码,主要是因为 ExtJS4 配备了一类新的系统,不向后兼容...ExtJS3 升级到 ExtJS4 需要修改大量代码,需要我们重新学习和适应 ExtJS4 的新特性和变化。
ExtJs中文API,比较全面!并且提供了很多的例子!! ExtJs中文API,比较全面!并且提供了很多的例子!! ExtJs中文API,比较全面!并且提供了很多的例子!! ExtJs中文API,比较全面!并且提供了很多的例子!!
9. **文件管理**:在上传成功后,EXTJS 还可以帮助管理和展示已上传的文件,例如在列表中显示文件名、大小、日期等信息。 `MultiFileUploadField.js` 文件是EXTJS框架中实现`MultiFileUploadField` 功能的具体代码...
绝对的ExtJS3.0中文API,本人在网上找了好久才找到的,在此奉献给大家!!解压后有30多兆!!
新手学习,初学extjs时用刚刚好,里边有三个例子,还有一个我自己写的例子(简单粗暴动态菜单),还有一个中文API
关于文件名称列表中的"ExtJS中文手册.doc",这表明手册以Microsoft Word文档格式提供,方便开发者打印或离线阅读。可能包含以下章节: 1. **基础概念**:介绍ExtJS的基本结构,如类系统、MVC模式、组件生命周期等。...
此压缩包中完全能实现的功能是在extjs中让本地照片预览,并且将地址传递给java后台,将图片文件以blob的形式存储到oracle数据库,并且可以默认将数据库中的数据第一次加载在预览框里(也就是从数据库中读出blob数据...