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. ...
随机推荐
- B - Broken Keyboard (a.k.a. Beiju Text) 数组模拟链表
You're typing a long text with a broken keyboard. Well it's not so badly broken. The only problem wi ...
- 可访问性(Accessibility) => 无障碍功能
了解无障碍功能及其范围和影响可令您成为更出色的网络开发者 复杂的一笔 https://developers.google.cn/web/fundamentals/accessibility/ ARIA ...
- 【Vue】---编写Vue插件流程---【巷子】
一.在Vue中编写插件流程 1.创建组件 components/message.vue <template> <div class="message" v-if= ...
- ThinkPHP框架 祖辈分的理解 【儿子 FenyeController】继承了【父亲 FuController】继承了【祖辈 Controller】的
注:系统自带的Controller方法代表的是祖辈 FuController控制器是自定义的,代表父亲... FenyeController控制器就代表着儿子 [儿子 FenyeController] ...
- JQuery登录代码
$(function () { $("#login").submit(function(event) { event.preventDefault(); if ($("# ...
- screen基本用法
当某些命令执行时间过长或者某些程序关闭shell后自动断开时,就能使用screen 1.安装yum -y install screen 2.输入screen命令进入screen控制台 3.输入scre ...
- Verilog HDL语言实现的单周期CPU设计(全部代码及其注释)
写在前面:本博客为本人原创,严禁任何形式的转载!本博客只允许放在博客园(.cnblogs.com),如果您在其他网站看到这篇博文,请通过下面这个唯一的合法链接转到原文! 本博客全网唯一合法URL:ht ...
- post/get in console of JSarray/js 数组详细操作方法及解析合集
https://juejin.im/post/5b0903b26fb9a07a9d70c7e0[ js 数组详细操作方法及解析合集 js array and for each https://blog ...
- java web指定主页
正常情况下主页是在web.xml里面配置欢迎页面,可以加个过滤器重定向就可以: public void doFilter(ServletRequest req, ServletResponse res ...
- Linux忘记密码常用的几种解决方法
原文链接:https://www.cnblogs.com/vurtne-lu/p/6550590.html 一. lilo引导1. 在出现 lilo: 提示时键入 linux single Boot: ...