ext/src/class/ClassManager.js

// todo 源码分析

重要:包含了Ext.define的定义

Ext.apply(Ext, {* the class' constructor.* @return {Object} instance* @member Ext* @method create*/create: alias(Manager, 'instantiate'),** @member Ext* @param {String} [name] The xtype of the widget to create.* @param {Object} [config] The configuration object for the widget constructor.* @return {Object} The widget instance*/widget: function(name, config) {// forms://      1: (xtype)//      2: (xtype, config)//      3: (config)//      4: (xtype, component)//      5: (component)//      var xtype = name,alias, className, T, load;if (typeof xtype != 'string') { // if (form 3 or 5)// first arg is config or componentconfig = name; // arguments[0]xtype = config.xtype;} else {config = config || {};}if (config.isComponent) {return config;}alias = 'widget.' + xtype;className = Manager.getNameByAlias(alias);// this is needed to support demand loading of the classif (!className) {load = true;}T = Manager.get(className);if (load || !T) {return Manager.instantiateByAlias(alias, config);}return new T(config);},/*** @inheritdoc Ext.ClassManager#instantiateByAlias* @member Ext* @method createByAlias*/createByAlias: alias(Manager, 'instantiateByAlias'),* required. Otherwise, the override, like the target class, is not included.** @param {String} className The class name to create in string dot-namespaced format, for example:* 'My.very.awesome.Class', 'FeedViewer.plugin.CoolPager'* It is highly recommended to follow this simple convention:*  - The root and the class name are 'CamelCased'*  - Everything else is lower-cased* Pass `null` to create an anonymous class.* @param {Object} data The key - value pairs of properties to apply to this class. Property names can be of any valid* strings, except those in the reserved listed below:*  - `mixins`*  - `statics`*  - `config`*  - `alias`*  - `self`*  - `singleton`*  - `alternateClassName`*  - `override`** @param {Function} createdFn Optional callback to execute after the class is created, the execution scope of which* (`this`) will be the newly created class itself.* @return {Ext.Base}* @member Ext*/define: function (className, data, createdFn) {//<debug>Ext.classSystemMonitor && Ext.classSystemMonitor(className, 'ClassManager#define', arguments);//</debug>if (data.override) {return Manager.createOverride.apply(Manager, arguments);}// create方法源码见后面return Manager.create.apply(Manager, arguments);},/*** Undefines a class defined using the #define method. Typically used* for unit testing where setting up and tearing down a class multiple* times is required.  For example:* *     // define a class*     Ext.define('Foo', {*        ...*     });*     *     // run test*     *     // undefine the class*     Ext.undefine('Foo');* @param {String} className The class name to undefine in string dot-namespaced format.* @private*/undefine: function(className) {//<debug>Ext.classSystemMonitor && Ext.classSystemMonitor(className, 'Ext.ClassManager#undefine', arguments);//</debug>var classes = Manager.classes,maps = Manager.maps,aliasToName = maps.aliasToName,nameToAliases = maps.nameToAliases,alternateToName = maps.alternateToName,nameToAlternates = maps.nameToAlternates,aliases = nameToAliases[className],alternates = nameToAlternates[className],parts, partCount, namespace, i;delete Manager.namespaceParseCache[className];delete nameToAliases[className];delete nameToAlternates[className];delete classes[className];if (aliases) {for (i = aliases.length; i--;) {delete aliasToName[aliases[i]];}}if (alternates) {for (i = alternates.length; i--; ) {delete alternateToName[alternates[i]];}}parts  = Manager.parseNamespace(className);partCount = parts.length - 1;namespace = parts[0];for (i = 1; i < partCount; i++) {namespace = namespace[parts[i]];if (!namespace) {return;}}// Old IE blows up on attempt to delete window propertytry {delete namespace[parts[partCount]];}catch (e) {namespace[parts[partCount]] = undefined;}},/*** @inheritdoc Ext.ClassManager#getName* @member Ext* @method getClassName*/getClassName: alias(Manager, 'getName'),/*** Returns the displayName property or className or object. When all else fails, returns "Anonymous".* @param {Object} object* @return {String}*/getDisplayName: function(object) {if (object) {if (object.displayName) {return object.displayName;}if (object.$name && object.$class) {return Ext.getClassName(object.$class) + '#' + object.$name;}if (object.$className) {return object.$className;}}return 'Anonymous';},/*** @inheritdoc Ext.ClassManager#getClass* @member Ext* @method getClass*/getClass: alias(Manager, 'getClass'),/*** Creates namespaces to be used for scoping variables and classes so that they are not global.* Specifying the last node of a namespace implicitly creates all other nodes. Usage:**     Ext.namespace('Company', 'Company.data');**     // equivalent and preferable to the above syntax*     Ext.ns('Company.data');**     Company.Widget = function() { ... };**     Company.data.CustomStore = function(config) { ... };** @param {String...} namespaces* @return {Object} The namespace object.* (If multiple arguments are passed, this will be the last namespace created)* @member Ext* @method namespace*/namespace: alias(Manager, 'createNamespaces')});

create方法源码,如下:

create: function(className, data, createdFn) {//<debug error>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(); // why?if (typeof data == 'function') {data = data(ctor);}//<debug>if (className) {ctor.displayName = className;}//</debug>data.$className = className;// 详见ExtClass源码return new Class(ctor, data, function() {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);});}

转载于:https://blog.51cto.com/wangyuelucky/1594628

Ext.ClassManager源码相关推荐

  1. extjs 方法执行顺序_透析Extjs的Ext.js源码(二)能在定义时就能执行的方法的写法 function(){...}...

    /** * 第二部分:能在定义时就能执行的方法的写法 function(){...}(); */ /** * 一.普通的方法的定义与执行 */ // 1-1.普通的方法定义,不带返回值的情况 fun ...

  2. JFinal 源码导读第八天(1) Db.tx 事物

    为什么80%的码农都做不了架构师?>>>    1.接上面的事物介绍 /*** IAtom support transaction of database.* It can be i ...

  3. 京东广告典型源码示例二

    广告资源链接 http://x.jd.com/exsites?spread_type=2&ad_ids=208:5&location_info=0&callback=getjj ...

  4. 京东典型广告推广源码示例一

    下面是一段京东广告推广的js源码,采用<iframe>标签内嵌到html中.html中事先有如下位置预留 <divid="Tech_F_Upright" styl ...

  5. Journey源码分析三:模板编译

    2019独角兽企业重金招聘Python工程师标准>>> 在Journey源码分析二:整体启动流程中提到了模板编译,这里详细说下启动流程 看下templates.Generate()源 ...

  6. Android Gradle Plugin 源码解析(上)

    一.源码依赖 本文基于: android gradle plugin版本: com.android.tools.build:gradle:2.3.0 gradle 版本:4.1 Gradle源码总共3 ...

  7. Python源码学习:启动流程简析

    Python源码分析 本文环境python2.5系列 参考书籍<<Python源码剖析>> Python简介: python主要是动态语言,虽然Python语言也有编译,生成中 ...

  8. C++官方自带可持久化平衡树rope的3000行源码

    C++官方rope3000行源码 // SGI's rope class -*- C++ -*-// Copyright (C) 2001-2015 Free Software Foundation, ...

  9. LNMP架构详解(2)——Mysql、PHP、Nginx源码编译过程

    前言 本文将介绍LNMP架构中Mysql.PHP.Nginx的源码编译过程:这时有人不仅会问:在我们使用的Linux系统中,可以从yum源中获得mysql.php,为什么要进行如此漫长复杂的过程进行编 ...

最新文章

  1. STM32 基础系列教程 42 - SDMMC+Fatfs
  2. 你学废了 Mybatis 动态批量修改吗?
  3. linux基础,文件目录管理,cd、rm、mkdir
  4. 【小白学PyTorch】16.TF2读取图片的方法
  5. 17校招真题题集(2)6-10
  6. 转:Java面试题以及答案精选(架构师面试题)-数据库专题
  7. python与机器学习(六)——支持向量机(SVM) 多层感知机(MLP)
  8. centos mysql 主从_CentOS 搭建 MySql 主从备份
  9. T-SQL 查询、修改数据表
  10. SOEM建立主站程序
  11. android dpi 修改,DPI修改
  12. scipy求极值代码
  13. 空间换时间和时间换空间
  14. 招行两地一卡——PayPal美元兑换人民币的最佳解决方案
  15. 百度糯米猴年初一夺冠  协同创新三大法器赢得漂亮
  16. Heart Rate Variability Analysis with the HRV Toolkit: Basic Time and Frequency Domain Measures
  17. 自然数因式分解最小和
  18. 基于JPEG压缩编码的数据压缩算法的研究与实现(转)
  19. C#动态创建lambda表达式
  20. Adobe Reader PDF阅读器闪退问题解决(批处理)

热门文章

  1. python存文件代码_Python文件读写保存操作的示例代码
  2. 计算机桌面有黑边怎么调整,电脑屏幕旁边有黑色框如何恢复_电脑两边黑边怎么还原-win7之家...
  3. 根据 sitemap 的规则[0],当前页面 [pages/index/index] 将被索引 提示
  4. XX市公共租赁住房信息管理系统模板
  5. Vue使用Element-ui按需引入大坑
  6. C#与NET实战 第5章 进程、线程与同步 节选
  7. asp.net 2.0 防止密码框被清空的解决方案
  8. python——C/C++python合♂体开发
  9. selinux + sudo +ssh +passwd
  10. 问题:HikariPool-1 - Shutdown initiated...的解决