Ext.define细节分析
自己写的其实还是不懂,
再看看别人写的吧
Extjs4 源码分析系列一 类的创建过程
https://www.cnblogs.com/creazyguagua/p/4302864.html
http://www.cnblogs.com/creazyguagua/p/4667768.html ExtJs4 makeCtor初步理解!
http://blog.csdn.net/wjy397/article/details/47321255 extjs底层源码实现继承分析
http://www.cnblogs.com/ouzilin/p/5164302.html Ext.define('MyApp.view.system.permission.Permission', {
extend : 'Ext.panel.Panel',
xtype : 'sys-permission',
requires: [
'MyApp.ux.Util',
'MyApp.model.SysRole'
],
viewModel: {
stores: {
roleStore : ZUtil.createStore('SysRole', 'SysRole/read'),
treeStore: ZUtil.createTreeStore('SysMainMenu/getMenuTree', {autoLoad :false})
}
},
controller: {
type: 'sys-permission'
},
title : '权限管理',
layout : 'border',
items : [ {
region : 'west',
xtype : 'grid',
width : 200,
title : '角色列表',
reference: 'grid',
split: true,
bind : {
store : '{roleStore}'
},
selModel : {
selType : 'rowmodel'
},
columns : [ {
text : 'ID',
dataIndex : 'id',
hidden: true
}, {
text : '角色名称',
dataIndex : 'name',
flex: 1
} ],
listeners : {
//activate : 'onRoleActivate',
itemclick : 'onRoleClick'
}
}, {
region : 'center',
xtype : 'treepanel',
title : '权限列表',
rootVisible: false,
reference: 'tree',
bind : {
store : '{treeStore}'
},
bbar: {
items: [{
text: '保存',
iconCls: 'Disk',
handler: 'onPermissionSave'
}]
}
} ]
});
Ext.define实际是调用
Ext.ClassManager(ClassManager.js) 的define
注意Manager = Ext.apply(new Ext.Inventory(), { 所以Ext.ClassManager实际上 is an instance of Ext.Inventory,又加了些东西?
define: function (className, data, createdFn) {
//<debug>
Ext.classSystemMonitor && Ext.classSystemMonitor(className, 'ClassManager#define', arguments);
//</debug>
if (data.override) {
Manager.classState[className] = 20;
return Manager.createOverride.apply(Manager, arguments);
}
Manager.classState[className] = 10;
return Manager.create.apply(Manager, arguments);
},
又调用了create:
/**
* Defines a class.
* @deprecated Use {@link Ext#define} instead, as that also supports creating overrides.
* @private
*/
create: function(className, data, createdFn) {
//<debug>
if (className != null && typeof className !== 'string') {
throw new Error("[Ext.define] Invalid class name '" + className + "' specified, must be a non-empty string");
}
//</debug> var ctor = makeCtor(className);
if (typeof data === 'function') {
data = data(ctor);
} //<debug>
if (className) {
if (Manager.classes[className]) {
Ext.log.warn("[Ext.define] Duplicate class name '" + className + "' specified, must be a non-empty string");
}
ctor.name = className;
}
//</debug> data.$className = className; return new Class(ctor, data, function() {
// 下面的createFn的处理估计是为了把类定义是的配置对象保存起来吧,
// 因为define一个自定义的类,就是为了设置上个性化的配置,从而Ext.create的时候直接得到个性化的实例
var postprocessorStack = data.postprocessors || Manager.defaultPostprocessors,
registeredPostprocessors = Manager.postprocessors,
postprocessors = [],
postprocessor, i, ln, j, subLn, postprocessorProperties, postprocessorProperty; delete data.postprocessors; for (i = 0,ln = postprocessorStack.length; i < ln; i++) {
postprocessor = postprocessorStack[i]; if (typeof postprocessor === 'string') {
postprocessor = registeredPostprocessors[postprocessor];
postprocessorProperties = postprocessor.properties; if (postprocessorProperties === true) {
postprocessors.push(postprocessor.fn);
}
else if (postprocessorProperties) {
for (j = 0,subLn = postprocessorProperties.length; j < subLn; j++) {
postprocessorProperty = postprocessorProperties[j]; if (data.hasOwnProperty(postprocessorProperty)) {
postprocessors.push(postprocessor.fn);
break;
}
}
}
}
else {
postprocessors.push(postprocessor);
}
} data.postprocessors = postprocessors;
data.createdFn = createdFn;
Manager.processCreate(className, this, data);
});
},
返回一个new Class(Class.js)
/**
* @method constructor
* Create a new anonymous class.
*
* @param {Object} data An object represent the properties of this class
* @param {Function} onCreated Optional, the callback function to be executed when this class is fully created.
* Note that the creation process can be asynchronous depending on the pre-processors used.
*
* @return {Ext.Base} The newly created class
*/
Ext.Class = ExtClass = function(Class, data, onCreated) {
if (typeof Class != 'function') {
onCreated = data;
data = Class;
Class = null;
} if (!data) {
data = {};
} Class = ExtClass.create(Class, data); ExtClass.process(Class, data, onCreated); return Class;
};
调用的ExtClass.create返回class
/**
* @private
*/
create: function (Class, data) {
var i = baseStaticMembers.length,
name; if (!Class) {
Class = makeCtor(
//<debug>
data.$className
//</debug>
);
} while (i--) {
name = baseStaticMembers[i];
Class[name] = Base[name];
} return Class;
},
调用的makeCtor
// Creates a constructor that has nothing extra in its scope chain.
function makeCtor (className) {
function constructor () {
// Opera has some problems returning from a constructor when Dragonfly isn't running. The || null seems to
// be sufficient to stop it misbehaving. Known to be required against 10.53, 11.51 and 11.61.
return this.constructor.apply(this, arguments) || null;
}
//<debug>
if (className) {
constructor.name = className;
}
//</debug>
return constructor;
}
好,不太懂了,貌似就是建了一个普通的函数对象,将类名作为name属性,估计是为了基于构造函数创建该类的实例用
看来Ext.define就是将类的描述属性信息注册到extjs的类体系中,等Ext.create的时候根据定义的类属性信息开始创建
Ext.define细节分析的更多相关文章
- Ext.create细节分析
var win1 = Ext.create('Ext.window.Window', { //实例化方法四 : 使用 完整的 Extjs 类名 width: 800, title: 'define t ...
- Extjs 学习总结-Ext.define自定义类
本教程整理了extjs的一些基本概念及其使用,包括自定义类(Ext.define).数据模型.代理等.本节介绍使用Ext.define自定义类 使用Ext.define自定义类 1. 首先看看js中自 ...
- Extjs-4.2.1(二)——使用Ext.define自定义类
鸣谢:http://www.cnblogs.com/youring2/archive/2013/08/22/3274135.html --------------------------------- ...
- rip路由协议 细节分析及实例配置【完整版】
rip路由协议 细节分析及实例配置[完整版] RIP呢,这是一个比较重要的知识点,所以它的知识覆盖面很广泛:但是呢,我将会对碰到的问题进行一些分析解刨(主要是为了帮助自己理清思维):也希望能够从中发现 ...
- Ext.define(override)
Ext.define(override)作用是:定义类的补丁(扩展或重写) 有3中使用方法,见附件 Ext.define(override).zip
- ExtJS 4.2 教程-03:使用Ext.define自定义类
转载自起飞网,原文地址:http://www.qeefee.com/extjs-course-3-define-classes ExtJS 4.2 教程-01:Hello ExtJS ExtJS 4. ...
- ExtJS学习------Ext.define的继承extend,用javascript实现相似Ext的继承
(1)Ext.define的继承extend 详细实例: Ext.onReady(function(){ //Sup Class 父类 Ext.define('Person',{ config:{ n ...
- ExtjS学习--------Ext.define定义类
Ext类Class的配置项:(注:Extjs的 的中文版帮助文档下载地址:http://download.csdn.net/detail/z1137730824/7748893 ExtJS配置文件和演 ...
- Ext学习之路——Ext.define
Ext.define('My.awesome.Class', { someProperty: 'something', someMethod: function() { alert(s + this. ...
随机推荐
- 数据结构与算法——基数排序简单Java实现
基数排序(radix sort)又称“桶子法”,在对多个正整数进行排序时可以使用.它的灵感来自于队列(Queue),它最独特的地方在于利用了数字的有穷性(阿拉伯数字只有0到9的10个). 基数排序使用 ...
- javaweb学习之建立简单网站
看到很多网站,论坛等,很实用,想做一个,比如中国图书网,它们的共同特点是运行在浏览器中. 最简单可行的技术就是jsp实现,但是jsp虽然可以在服务器端显示,在客户端连接数据库,且客户端和服务器端要完成 ...
- Flask web开发之路十
首先介绍循环引用的问题: 当一个模块需要引用另一个模块的类,而另一个模块又需要引用这个模块的类时,就出现了循环引用,而没法导入类,这时候可以切断其中一条引用路径,增加一个模块 项目结构: models ...
- CCPC-Wannafly Winter Camp Day7 D---二次函数【数论】【构造】
题意: 有三个二次函数,分别是$x^2 + a_1x + b_1$, $x^2 + a_2x + b_2$, $x^2 + a_3x + b_3$ 现在要找三个整数$x_1, x_2, x_3$, 使 ...
- hdu2243 考研路茫茫——单词情结【AC自动机】【矩阵快速幂】
考研路茫茫——单词情结 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- [No0000176]Git常用命令速查表(收藏大全)
名词 master: 默认开发分支 origin: 默认远程版本库 Index / Stage:暂存区 Workspace:工作区 Repository:仓库区(或本地仓库) Remote:远程仓库 ...
- hbase本地模式-安装及基本测试
解压缩hbase二进制安装文件到/opt目录下: #tar -zxvf hbase-0.98.6-cdh5.3.6.tar.gz -C /opt/cdh-5.3.6/ 编辑配置文件,这里仅配置数据目录 ...
- 关于初识Java整理
- English class 81:How Vulnerability can make our lives better?
1,can we come off as weak if we show imperfections? 2,The first thing I look for in you and the last ...
- 子分区 复合分区 Subpartitioning
https://dev.mysql.com/doc/refman/8.0/en/partitioning-subpartitions.html