Base.html 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-Base'>/**
  19. </span> * @author Jacky Nguyen &lt;jacky@sencha.com&gt;
  20. * @docauthor Jacky Nguyen &lt;jacky@sencha.com&gt;
  21. * @class Ext.Base
  22. *
  23. * The root of all classes created with {@link Ext#define}.
  24. *
  25. * Ext.Base is the building block of all Ext classes. All classes in Ext inherit from Ext.Base.
  26. * All prototype and static members of this class are inherited by all other classes.
  27. */
  28. (function(flexSetter) {
  29. var noArgs = [],
  30. Base = function(){};
  31. // These static properties will be copied to every newly created class with {@link Ext#define}
  32. Ext.apply(Base, {
  33. $className: 'Ext.Base',
  34. $isClass: true,
  35. <span id='Ext-Base-static-method-create'> /**
  36. </span> * Create a new instance of this Class.
  37. *
  38. * Ext.define('My.cool.Class', {
  39. * ...
  40. * });
  41. *
  42. * My.cool.Class.create({
  43. * someConfig: true
  44. * });
  45. *
  46. * All parameters are passed to the constructor of the class.
  47. *
  48. * @return {Object} the created instance.
  49. * @static
  50. * @inheritable
  51. */
  52. create: function() {
  53. return Ext.create.apply(Ext, [this].concat(Array.prototype.slice.call(arguments, 0)));
  54. },
  55. <span id='Ext-Base-static-method-extend'> /**
  56. </span> * @private
  57. * @static
  58. * @inheritable
  59. * @param config
  60. */
  61. extend: function(parent) {
  62. var parentPrototype = parent.prototype,
  63. basePrototype, prototype, i, ln, name, statics;
  64. prototype = this.prototype = Ext.Object.chain(parentPrototype);
  65. prototype.self = this;
  66. this.superclass = prototype.superclass = parentPrototype;
  67. if (!parent.$isClass) {
  68. basePrototype = Ext.Base.prototype;
  69. for (i in basePrototype) {
  70. if (i in prototype) {
  71. prototype[i] = basePrototype[i];
  72. }
  73. }
  74. }
  75. //&lt;feature classSystem.inheritableStatics&gt;
  76. // Statics inheritance
  77. statics = parentPrototype.$inheritableStatics;
  78. if (statics) {
  79. for (i = 0,ln = statics.length; i &lt; ln; i++) {
  80. name = statics[i];
  81. if (!this.hasOwnProperty(name)) {
  82. this[name] = parent[name];
  83. }
  84. }
  85. }
  86. //&lt;/feature&gt;
  87. if (parent.$onExtended) {
  88. this.$onExtended = parent.$onExtended.slice();
  89. }
  90. //&lt;feature classSystem.config&gt;
  91. prototype.config = new prototype.configClass();
  92. prototype.initConfigList = prototype.initConfigList.slice();
  93. prototype.initConfigMap = Ext.clone(prototype.initConfigMap);
  94. prototype.configMap = Ext.Object.chain(prototype.configMap);
  95. //&lt;/feature&gt;
  96. },
  97. <span id='Ext-Base-static-property-S-onExtended'> /**
  98. </span> * @private
  99. * @static
  100. * @inheritable
  101. */
  102. $onExtended: [],
  103. <span id='Ext-Base-static-method-triggerExtended'> /**
  104. </span> * @private
  105. * @static
  106. * @inheritable
  107. */
  108. triggerExtended: function() {
  109. var callbacks = this.$onExtended,
  110. ln = callbacks.length,
  111. i, callback;
  112. if (ln &gt; 0) {
  113. for (i = 0; i &lt; ln; i++) {
  114. callback = callbacks[i];
  115. callback.fn.apply(callback.scope || this, arguments);
  116. }
  117. }
  118. },
  119. <span id='Ext-Base-static-method-onExtended'> /**
  120. </span> * @private
  121. * @static
  122. * @inheritable
  123. */
  124. onExtended: function(fn, scope) {
  125. this.$onExtended.push({
  126. fn: fn,
  127. scope: scope
  128. });
  129. return this;
  130. },
  131. <span id='Ext-Base-static-method-addConfig'> /**
  132. </span> * @private
  133. * @static
  134. * @inheritable
  135. * @param config
  136. */
  137. addConfig: function(config, fullMerge) {
  138. var prototype = this.prototype,
  139. configNameCache = Ext.Class.configNameCache,
  140. hasConfig = prototype.configMap,
  141. initConfigList = prototype.initConfigList,
  142. initConfigMap = prototype.initConfigMap,
  143. defaultConfig = prototype.config,
  144. initializedName, name, value;
  145. for (name in config) {
  146. if (config.hasOwnProperty(name)) {
  147. if (!hasConfig[name]) {
  148. hasConfig[name] = true;
  149. }
  150. value = config[name];
  151. initializedName = configNameCache[name].initialized;
  152. if (!initConfigMap[name] &amp;&amp; value !== null &amp;&amp; !prototype[initializedName]) {
  153. initConfigMap[name] = true;
  154. initConfigList.push(name);
  155. }
  156. }
  157. }
  158. if (fullMerge) {
  159. Ext.merge(defaultConfig, config);
  160. }
  161. else {
  162. Ext.mergeIf(defaultConfig, config);
  163. }
  164. prototype.configClass = Ext.Object.classify(defaultConfig);
  165. },
  166. <span id='Ext-Base-static-method-addStatics'> /**
  167. </span> * Add / override static properties of this class.
  168. *
  169. * Ext.define('My.cool.Class', {
  170. * ...
  171. * });
  172. *
  173. * My.cool.Class.addStatics({
  174. * someProperty: 'someValue', // My.cool.Class.someProperty = 'someValue'
  175. * method1: function() { ... }, // My.cool.Class.method1 = function() { ... };
  176. * method2: function() { ... } // My.cool.Class.method2 = function() { ... };
  177. * });
  178. *
  179. * @param {Object} members
  180. * @return {Ext.Base} this
  181. * @static
  182. * @inheritable
  183. */
  184. addStatics: function(members) {
  185. var member, name;
  186. for (name in members) {
  187. if (members.hasOwnProperty(name)) {
  188. member = members[name];
  189. //&lt;debug&gt;
  190. if (typeof member == 'function') {
  191. member.displayName = Ext.getClassName(this) + '.' + name;
  192. }
  193. //&lt;/debug&gt;
  194. this[name] = member;
  195. }
  196. }
  197. return this;
  198. },
  199. <span id='Ext-Base-static-method-addInheritableStatics'> /**
  200. </span> * @private
  201. * @static
  202. * @inheritable
  203. * @param {Object} members
  204. */
  205. addInheritableStatics: function(members) {
  206. var inheritableStatics,
  207. hasInheritableStatics,
  208. prototype = this.prototype,
  209. name, member;
  210. inheritableStatics = prototype.$inheritableStatics;
  211. hasInheritableStatics = prototype.$hasInheritableStatics;
  212. if (!inheritableStatics) {
  213. inheritableStatics = prototype.$inheritableStatics = [];
  214. hasInheritableStatics = prototype.$hasInheritableStatics = {};
  215. }
  216. for (name in members) {
  217. if (members.hasOwnProperty(name)) {
  218. member = members[name];
  219. //&lt;debug&gt;
  220. if (typeof member == 'function') {
  221. member.displayName = Ext.getClassName(this) + '.' + name;
  222. }
  223. //&lt;/debug&gt;
  224. this[name] = member;
  225. if (!hasInheritableStatics[name]) {
  226. hasInheritableStatics[name] = true;
  227. inheritableStatics.push(name);
  228. }
  229. }
  230. }
  231. return this;
  232. },
  233. <span id='Ext-Base-static-method-addMembers'> /**
  234. </span> * Add methods / properties to the prototype of this class.
  235. *
  236. * Ext.define('My.awesome.Cat', {
  237. * constructor: function() {
  238. * ...
  239. * }
  240. * });
  241. *
  242. * My.awesome.Cat.addMembers({
  243. * meow: function() {
  244. * alert('Meowww...');
  245. * }
  246. * });
  247. *
  248. * var kitty = new My.awesome.Cat;
  249. * kitty.meow();
  250. *
  251. * @param {Object} members
  252. * @static
  253. * @inheritable
  254. */
  255. addMembers: function(members) {
  256. var prototype = this.prototype,
  257. enumerables = Ext.enumerables,
  258. names = [],
  259. i, ln, name, member;
  260. for (name in members) {
  261. names.push(name);
  262. }
  263. if (enumerables) {
  264. names.push.apply(names, enumerables);
  265. }
  266. for (i = 0,ln = names.length; i &lt; ln; i++) {
  267. name = names[i];
  268. if (members.hasOwnProperty(name)) {
  269. member = members[name];
  270. if (typeof member == 'function' &amp;&amp; !member.$isClass &amp;&amp; member !== Ext.emptyFn) {
  271. member.$owner = this;
  272. member.$name = name;
  273. //&lt;debug&gt;
  274. member.displayName = (this.$className || '') + '#' + name;
  275. //&lt;/debug&gt;
  276. }
  277. prototype[name] = member;
  278. }
  279. }
  280. return this;
  281. },
  282. <span id='Ext-Base-static-method-addMember'> /**
  283. </span> * @private
  284. * @static
  285. * @inheritable
  286. * @param name
  287. * @param member
  288. */
  289. addMember: function(name, member) {
  290. if (typeof member == 'function' &amp;&amp; !member.$isClass &amp;&amp; member !== Ext.emptyFn) {
  291. member.$owner = this;
  292. member.$name = name;
  293. //&lt;debug&gt;
  294. member.displayName = (this.$className || '') + '#' + name;
  295. //&lt;/debug&gt;
  296. }
  297. this.prototype[name] = member;
  298. return this;
  299. },
  300. <span id='Ext-Base-static-method-implement'> /**
  301. </span> * Adds members to class.
  302. * @static
  303. * @inheritable
  304. * @deprecated 4.1 Use {@link #addMembers} instead.
  305. */
  306. implement: function() {
  307. this.addMembers.apply(this, arguments);
  308. },
  309. <span id='Ext-Base-static-method-borrow'> /**
  310. </span> * Borrow another class' members to the prototype of this class.
  311. *
  312. * Ext.define('Bank', {
  313. * money: '$$$',
  314. * printMoney: function() {
  315. * alert('$$$$$$$');
  316. * }
  317. * });
  318. *
  319. * Ext.define('Thief', {
  320. * ...
  321. * });
  322. *
  323. * Thief.borrow(Bank, ['money', 'printMoney']);
  324. *
  325. * var steve = new Thief();
  326. *
  327. * alert(steve.money); // alerts '$$$'
  328. * steve.printMoney(); // alerts '$$$$$$$'
  329. *
  330. * @param {Ext.Base} fromClass The class to borrow members from
  331. * @param {Array/String} members The names of the members to borrow
  332. * @return {Ext.Base} this
  333. * @static
  334. * @inheritable
  335. * @private
  336. */
  337. borrow: function(fromClass, members) {
  338. var prototype = this.prototype,
  339. fromPrototype = fromClass.prototype,
  340. //&lt;debug&gt;
  341. className = Ext.getClassName(this),
  342. //&lt;/debug&gt;
  343. i, ln, name, fn, toBorrow;
  344. members = Ext.Array.from(members);
  345. for (i = 0,ln = members.length; i &lt; ln; i++) {
  346. name = members[i];
  347. toBorrow = fromPrototype[name];
  348. if (typeof toBorrow == 'function') {
  349. fn = Ext.Function.clone(toBorrow);
  350. //&lt;debug&gt;
  351. if (className) {
  352. fn.displayName = className + '#' + name;
  353. }
  354. //&lt;/debug&gt;
  355. fn.$owner = this;
  356. fn.$name = name;
  357. prototype[name] = fn;
  358. }
  359. else {
  360. prototype[name] = toBorrow;
  361. }
  362. }
  363. return this;
  364. },
  365. <span id='Ext-Base-static-method-override'> /**
  366. </span> * Override members of this class. Overridden methods can be invoked via
  367. * {@link Ext.Base#callParent}.
  368. *
  369. * Ext.define('My.Cat', {
  370. * constructor: function() {
  371. * alert(&quot;I'm a cat!&quot;);
  372. * }
  373. * });
  374. *
  375. * My.Cat.override({
  376. * constructor: function() {
  377. * alert(&quot;I'm going to be a cat!&quot;);
  378. *
  379. * this.callParent(arguments);
  380. *
  381. * alert(&quot;Meeeeoooowwww&quot;);
  382. * }
  383. * });
  384. *
  385. * var kitty = new My.Cat(); // alerts &quot;I'm going to be a cat!&quot;
  386. * // alerts &quot;I'm a cat!&quot;
  387. * // alerts &quot;Meeeeoooowwww&quot;
  388. *
  389. * As of 4.1, direct use of this method is deprecated. Use {@link Ext#define Ext.define}
  390. * instead:
  391. *
  392. * Ext.define('My.CatOverride', {
  393. * override: 'My.Cat',
  394. * constructor: function() {
  395. * alert(&quot;I'm going to be a cat!&quot;);
  396. *
  397. * this.callParent(arguments);
  398. *
  399. * alert(&quot;Meeeeoooowwww&quot;);
  400. * }
  401. * });
  402. *
  403. * The above accomplishes the same result but can be managed by the {@link Ext.Loader}
  404. * which can properly order the override and its target class and the build process
  405. * can determine whether the override is needed based on the required state of the
  406. * target class (My.Cat).
  407. *
  408. * @param {Object} members The properties to add to this class. This should be
  409. * specified as an object literal containing one or more properties.
  410. * @return {Ext.Base} this class
  411. * @static
  412. * @inheritable
  413. * @markdown
  414. * @deprecated 4.1.0 Use {@link Ext#define Ext.define} instead
  415. */
  416. override: function(members) {
  417. var me = this,
  418. enumerables = Ext.enumerables,
  419. target = me.prototype,
  420. cloneFunction = Ext.Function.clone,
  421. name, index, member, statics, names, previous;
  422. if (arguments.length === 2) {
  423. name = members;
  424. members = {};
  425. members[name] = arguments[1];
  426. enumerables = null;
  427. }
  428. do {
  429. names = []; // clean slate for prototype (1st pass) and static (2nd pass)
  430. statics = null; // not needed 1st pass, but needs to be cleared for 2nd pass
  431. for (name in members) { // hasOwnProperty is checked in the next loop...
  432. if (name == 'statics') {
  433. statics = members[name];
  434. } else if (name == 'config') {
  435. me.addConfig(members[name], true);
  436. } else {
  437. names.push(name);
  438. }
  439. }
  440. if (enumerables) {
  441. names.push.apply(names, enumerables);
  442. }
  443. for (index = names.length; index--; ) {
  444. name = names[index];
  445. if (members.hasOwnProperty(name)) {
  446. member = members[name];
  447. if (typeof member == 'function' &amp;&amp; !member.$className &amp;&amp; member !== Ext.emptyFn) {
  448. if (typeof member.$owner != 'undefined') {
  449. member = cloneFunction(member);
  450. }
  451. //&lt;debug&gt;
  452. if (me.$className) {
  453. member.displayName = me.$className + '#' + name;
  454. }
  455. //&lt;/debug&gt;
  456. member.$owner = me;
  457. member.$name = name;
  458. previous = target[name];
  459. if (previous) {
  460. member.$previous = previous;
  461. }
  462. }
  463. target[name] = member;
  464. }
  465. }
  466. target = me; // 2nd pass is for statics
  467. members = statics; // statics will be null on 2nd pass
  468. } while (members);
  469. return this;
  470. },
  471. // Documented downwards
  472. callParent: function(args) {
  473. var method;
  474. // This code is intentionally inlined for the least number of debugger stepping
  475. return (method = this.callParent.caller) &amp;&amp; (method.$previous ||
  476. ((method = method.$owner ? method : method.caller) &amp;&amp;
  477. method.$owner.superclass.$class[method.$name])).apply(this, args || noArgs);
  478. },
  479. //&lt;feature classSystem.mixins&gt;
  480. <span id='Ext-Base-static-method-mixin'> /**
  481. </span> * Used internally by the mixins pre-processor
  482. * @private
  483. * @static
  484. * @inheritable
  485. */
  486. mixin: function(name, mixinClass) {
  487. var mixin = mixinClass.prototype,
  488. prototype = this.prototype,
  489. key;
  490. if (typeof mixin.onClassMixedIn != 'undefined') {
  491. mixin.onClassMixedIn.call(mixinClass, this);
  492. }
  493. if (!prototype.hasOwnProperty('mixins')) {
  494. if ('mixins' in prototype) {
  495. prototype.mixins = Ext.Object.chain(prototype.mixins);
  496. }
  497. else {
  498. prototype.mixins = {};
  499. }
  500. }
  501. for (key in mixin) {
  502. if (key === 'mixins') {
  503. Ext.merge(prototype.mixins, mixin[key]);
  504. }
  505. else if (typeof prototype[key] == 'undefined' &amp;&amp; key != 'mixinId' &amp;&amp; key != 'config') {
  506. prototype[key] = mixin[key];
  507. }
  508. }
  509. //&lt;feature classSystem.config&gt;
  510. if ('config' in mixin) {
  511. this.addConfig(mixin.config, false);
  512. }
  513. //&lt;/feature&gt;
  514. prototype.mixins[name] = mixin;
  515. },
  516. //&lt;/feature&gt;
  517. <span id='Ext-Base-static-method-getName'> /**
  518. </span> * Get the current class' name in string format.
  519. *
  520. * Ext.define('My.cool.Class', {
  521. * constructor: function() {
  522. * alert(this.self.getName()); // alerts 'My.cool.Class'
  523. * }
  524. * });
  525. *
  526. * My.cool.Class.getName(); // 'My.cool.Class'
  527. *
  528. * @return {String} className
  529. * @static
  530. * @inheritable
  531. */
  532. getName: function() {
  533. return Ext.getClassName(this);
  534. },
  535. <span id='Ext-Base-static-method-createAlias'> /**
  536. </span> * Create aliases for existing prototype methods. Example:
  537. *
  538. * Ext.define('My.cool.Class', {
  539. * method1: function() { ... },
  540. * method2: function() { ... }
  541. * });
  542. *
  543. * var test = new My.cool.Class();
  544. *
  545. * My.cool.Class.createAlias({
  546. * method3: 'method1',
  547. * method4: 'method2'
  548. * });
  549. *
  550. * test.method3(); // test.method1()
  551. *
  552. * My.cool.Class.createAlias('method5', 'method3');
  553. *
  554. * test.method5(); // test.method3() -&gt; test.method1()
  555. *
  556. * @param {String/Object} alias The new method name, or an object to set multiple aliases. See
  557. * {@link Ext.Function#flexSetter flexSetter}
  558. * @param {String/Object} origin The original method name
  559. * @static
  560. * @inheritable
  561. * @method
  562. */
  563. createAlias: flexSetter(function(alias, origin) {
  564. this.override(alias, function() {
  565. return this[origin].apply(this, arguments);
  566. });
  567. }),
  568. <span id='Ext-Base-static-method-addXtype'> /**
  569. </span> * @private
  570. * @static
  571. * @inheritable
  572. */
  573. addXtype: function(xtype) {
  574. var prototype = this.prototype,
  575. xtypesMap = prototype.xtypesMap,
  576. xtypes = prototype.xtypes,
  577. xtypesChain = prototype.xtypesChain;
  578. if (!prototype.hasOwnProperty('xtypesMap')) {
  579. xtypesMap = prototype.xtypesMap = Ext.merge({}, prototype.xtypesMap || {});
  580. xtypes = prototype.xtypes = prototype.xtypes ? [].concat(prototype.xtypes) : [];
  581. xtypesChain = prototype.xtypesChain = prototype.xtypesChain ? [].concat(prototype.xtypesChain) : [];
  582. prototype.xtype = xtype;
  583. }
  584. if (!xtypesMap[xtype]) {
  585. xtypesMap[xtype] = true;
  586. xtypes.push(xtype);
  587. xtypesChain.push(xtype);
  588. Ext.ClassManager.setAlias(this, 'widget.' + xtype);
  589. }
  590. return this;
  591. }
  592. });
  593. Base.implement({
  594. <span id='Ext-Base-property-isInstance'> /** @private */
  595. </span> isInstance: true,
  596. <span id='Ext-Base-property-S-className'> /** @private */
  597. </span> $className: 'Ext.Base',
  598. <span id='Ext-Base-method-configClass'> /** @private */
  599. </span> configClass: Ext.emptyFn,
  600. <span id='Ext-Base-property-initConfigList'> /** @private */
  601. </span> initConfigList: [],
  602. <span id='Ext-Base-property-configMap'> /** @private */
  603. </span> configMap: {},
  604. <span id='Ext-Base-property-initConfigMap'> /** @private */
  605. </span> initConfigMap: {},
  606. <span id='Ext-Base-method-statics'> /**
  607. </span> * Get the reference to the class from which this object was instantiated. Note that unlike {@link Ext.Base#self},
  608. * `this.statics()` is scope-independent and it always returns the class from which it was called, regardless of what
  609. * `this` points to during run-time
  610. *
  611. * Ext.define('My.Cat', {
  612. * statics: {
  613. * totalCreated: 0,
  614. * speciesName: 'Cat' // My.Cat.speciesName = 'Cat'
  615. * },
  616. *
  617. * constructor: function() {
  618. * var statics = this.statics();
  619. *
  620. * alert(statics.speciesName); // always equals to 'Cat' no matter what 'this' refers to
  621. * // equivalent to: My.Cat.speciesName
  622. *
  623. * alert(this.self.speciesName); // dependent on 'this'
  624. *
  625. * statics.totalCreated++;
  626. * },
  627. *
  628. * clone: function() {
  629. * var cloned = new this.self; // dependent on 'this'
  630. *
  631. * cloned.groupName = this.statics().speciesName; // equivalent to: My.Cat.speciesName
  632. *
  633. * return cloned;
  634. * }
  635. * });
  636. *
  637. *
  638. * Ext.define('My.SnowLeopard', {
  639. * extend: 'My.Cat',
  640. *
  641. * statics: {
  642. * speciesName: 'Snow Leopard' // My.SnowLeopard.speciesName = 'Snow Leopard'
  643. * },
  644. *
  645. * constructor: function() {
  646. * this.callParent();
  647. * }
  648. * });
  649. *
  650. * var cat = new My.Cat(); // alerts 'Cat', then alerts 'Cat'
  651. *
  652. * var snowLeopard = new My.SnowLeopard(); // alerts 'Cat', then alerts 'Snow Leopard'
  653. *
  654. * var clone = snowLeopard.clone();
  655. * alert(Ext.getClassName(clone)); // alerts 'My.SnowLeopard'
  656. * alert(clone.groupName); // alerts 'Cat'
  657. *
  658. * alert(My.Cat.totalCreated); // alerts 3
  659. *
  660. * @protected
  661. * @return {Ext.Class}
  662. */
  663. statics: function() {
  664. var method = this.statics.caller,
  665. self = this.self;
  666. if (!method) {
  667. return self;
  668. }
  669. return method.$owner;
  670. },
  671. <span id='Ext-Base-method-callParent'> /**
  672. </span> * Call the &quot;parent&quot; method of the current method. That is the method previously
  673. * overridden by derivation or by an override (see {@link Ext#define}).
  674. *
  675. * Ext.define('My.Base', {
  676. * constructor: function (x) {
  677. * this.x = x;
  678. * },
  679. *
  680. * statics: {
  681. * method: function (x) {
  682. * return x;
  683. * }
  684. * }
  685. * });
  686. *
  687. * Ext.define('My.Derived', {
  688. * extend: 'My.Base',
  689. *
  690. * constructor: function () {
  691. * this.callParent([21]);
  692. * }
  693. * });
  694. *
  695. * var obj = new My.Derived();
  696. *
  697. * alert(obj.x); // alerts 21
  698. *
  699. * This can be used with an override as follows:
  700. *
  701. * Ext.define('My.DerivedOverride', {
  702. * override: 'My.Derived',
  703. *
  704. * constructor: function (x) {
  705. * this.callParent([x*2]); // calls original My.Derived constructor
  706. * }
  707. * });
  708. *
  709. * var obj = new My.Derived();
  710. *
  711. * alert(obj.x); // now alerts 42
  712. *
  713. * This also works with static methods.
  714. *
  715. * Ext.define('My.Derived2', {
  716. * extend: 'My.Base',
  717. *
  718. * statics: {
  719. * method: function (x) {
  720. * return this.callParent([x*2]); // calls My.Base.method
  721. * }
  722. * }
  723. * });
  724. *
  725. * alert(My.Base.method(10); // alerts 10
  726. * alert(My.Derived2.method(10); // alerts 20
  727. *
  728. * Lastly, it also works with overridden static methods.
  729. *
  730. * Ext.define('My.Derived2Override', {
  731. * override: 'My.Derived2',
  732. *
  733. * statics: {
  734. * method: function (x) {
  735. * return this.callParent([x*2]); // calls My.Derived2.method
  736. * }
  737. * }
  738. * });
  739. *
  740. * alert(My.Derived2.method(10); // now alerts 40
  741. *
  742. * @protected
  743. * @param {Array/Arguments} args The arguments, either an array or the `arguments` object
  744. * from the current method, for example: `this.callParent(arguments)`
  745. * @return {Object} Returns the result of calling the parent method
  746. */
  747. callParent: function(args) {
  748. // NOTE: this code is deliberately as few expressions (and no function calls)
  749. // as possible so that a debugger can skip over this noise with the minimum number
  750. // of steps. Basically, just hit Step Into until you are where you really wanted
  751. // to be.
  752. var method,
  753. superMethod = (method = this.callParent.caller) &amp;&amp; (method.$previous ||
  754. ((method = method.$owner ? method : method.caller) &amp;&amp;
  755. method.$owner.superclass[method.$name]));
  756. //&lt;debug error&gt;
  757. if (!superMethod) {
  758. method = this.callParent.caller;
  759. var parentClass, methodName;
  760. if (!method.$owner) {
  761. if (!method.caller) {
  762. throw new Error(&quot;Attempting to call a protected method from the public scope, which is not allowed&quot;);
  763. }
  764. method = method.caller;
  765. }
  766. parentClass = method.$owner.superclass;
  767. methodName = method.$name;
  768. if (!(methodName in parentClass)) {
  769. throw new Error(&quot;this.callParent() was called but there's no such method (&quot; + methodName +
  770. &quot;) found in the parent class (&quot; + (Ext.getClassName(parentClass) || 'Object') + &quot;)&quot;);
  771. }
  772. }
  773. //&lt;/debug&gt;
  774. return superMethod.apply(this, args || noArgs);
  775. },
  776. <span id='Ext-Base-property-self'> /**
  777. </span> * @property {Ext.Class} self
  778. *
  779. * Get the reference to the current class from which this object was instantiated. Unlike {@link Ext.Base#statics},
  780. * `this.self` is scope-dependent and it's meant to be used for dynamic inheritance. See {@link Ext.Base#statics}
  781. * for a detailed comparison
  782. *
  783. * Ext.define('My.Cat', {
  784. * statics: {
  785. * speciesName: 'Cat' // My.Cat.speciesName = 'Cat'
  786. * },
  787. *
  788. * constructor: function() {
  789. * alert(this.self.speciesName); // dependent on 'this'
  790. * },
  791. *
  792. * clone: function() {
  793. * return new this.self();
  794. * }
  795. * });
  796. *
  797. *
  798. * Ext.define('My.SnowLeopard', {
  799. * extend: 'My.Cat',
  800. * statics: {
  801. * speciesName: 'Snow Leopard' // My.SnowLeopard.speciesName = 'Snow Leopard'
  802. * }
  803. * });
  804. *
  805. * var cat = new My.Cat(); // alerts 'Cat'
  806. * var snowLeopard = new My.SnowLeopard(); // alerts 'Snow Leopard'
  807. *
  808. * var clone = snowLeopard.clone();
  809. * alert(Ext.getClassName(clone)); // alerts 'My.SnowLeopard'
  810. *
  811. * @protected
  812. */
  813. self: Base,
  814. // Default constructor, simply returns `this`
  815. constructor: function() {
  816. return this;
  817. },
  818. //&lt;feature classSystem.config&gt;
  819. <span id='Ext-Base-method-initConfig'> /**
  820. </span> * Initialize configuration for this class. a typical example:
  821. *
  822. * Ext.define('My.awesome.Class', {
  823. * // The default config
  824. * config: {
  825. * name: 'Awesome',
  826. * isAwesome: true
  827. * },
  828. *
  829. * constructor: function(config) {
  830. * this.initConfig(config);
  831. * }
  832. * });
  833. *
  834. * var awesome = new My.awesome.Class({
  835. * name: 'Super Awesome'
  836. * });
  837. *
  838. * alert(awesome.getName()); // 'Super Awesome'
  839. *
  840. * @protected
  841. * @param {Object} config
  842. * @return {Ext.Base} this
  843. */
  844. initConfig: function(config) {
  845. var instanceConfig = config,
  846. configNameCache = Ext.Class.configNameCache,
  847. defaultConfig = new this.configClass(),
  848. defaultConfigList = this.initConfigList,
  849. hasConfig = this.configMap,
  850. nameMap, i, ln, name, initializedName;
  851. this.initConfig = Ext.emptyFn;
  852. this.initialConfig = instanceConfig || {};
  853. this.config = config = (instanceConfig) ? Ext.merge(defaultConfig, config) : defaultConfig;
  854. if (instanceConfig) {
  855. defaultConfigList = defaultConfigList.slice();
  856. for (name in instanceConfig) {
  857. if (hasConfig[name]) {
  858. if (instanceConfig[name] !== null) {
  859. defaultConfigList.push(name);
  860. this[configNameCache[name].initialized] = false;
  861. }
  862. }
  863. }
  864. }
  865. for (i = 0,ln = defaultConfigList.length; i &lt; ln; i++) {
  866. name = defaultConfigList[i];
  867. nameMap = configNameCache[name];
  868. initializedName = nameMap.initialized;
  869. if (!this[initializedName]) {
  870. this[initializedName] = true;
  871. this[nameMap.set].call(this, config[name]);
  872. }
  873. }
  874. return this;
  875. },
  876. <span id='Ext-Base-method-hasConfig'> /**
  877. </span> * @private
  878. * @param config
  879. */
  880. hasConfig: function(name) {
  881. return Boolean(this.configMap[name]);
  882. },
  883. <span id='Ext-Base-method-setConfig'> /**
  884. </span> * @private
  885. */
  886. setConfig: function(config, applyIfNotSet) {
  887. if (!config) {
  888. return this;
  889. }
  890. var configNameCache = Ext.Class.configNameCache,
  891. currentConfig = this.config,
  892. hasConfig = this.configMap,
  893. initialConfig = this.initialConfig,
  894. name, value;
  895. applyIfNotSet = Boolean(applyIfNotSet);
  896. for (name in config) {
  897. if (applyIfNotSet &amp;&amp; initialConfig.hasOwnProperty(name)) {
  898. continue;
  899. }
  900. value = config[name];
  901. currentConfig[name] = value;
  902. if (hasConfig[name]) {
  903. this[configNameCache[name].set](value);
  904. }
  905. }
  906. return this;
  907. },
  908. <span id='Ext-Base-method-getConfig'> /**
  909. </span> * @private
  910. * @param name
  911. */
  912. getConfig: function(name) {
  913. var configNameCache = Ext.Class.configNameCache;
  914. return this[configNameCache[name].get]();
  915. },
  916. <span id='Ext-Base-method-getInitialConfig'> /**
  917. </span> * Returns the initial configuration passed to constructor when instantiating
  918. * this class.
  919. * @param {String} [name] Name of the config option to return.
  920. * @return {Object/Mixed} The full config object or a single config value
  921. * when `name` parameter specified.
  922. */
  923. getInitialConfig: function(name) {
  924. var config = this.config;
  925. if (!name) {
  926. return config;
  927. }
  928. else {
  929. return config[name];
  930. }
  931. },
  932. <span id='Ext-Base-method-onConfigUpdate'> /**
  933. </span> * @private
  934. * @param names
  935. * @param callback
  936. * @param scope
  937. */
  938. onConfigUpdate: function(names, callback, scope) {
  939. var self = this.self,
  940. //&lt;debug&gt;
  941. className = self.$className,
  942. //&lt;/debug&gt;
  943. i, ln, name,
  944. updaterName, updater, newUpdater;
  945. names = Ext.Array.from(names);
  946. scope = scope || this;
  947. for (i = 0,ln = names.length; i &lt; ln; i++) {
  948. name = names[i];
  949. updaterName = 'update' + Ext.String.capitalize(name);
  950. updater = this[updaterName] || Ext.emptyFn;
  951. newUpdater = function() {
  952. updater.apply(this, arguments);
  953. scope[callback].apply(scope, arguments);
  954. };
  955. newUpdater.$name = updaterName;
  956. newUpdater.$owner = self;
  957. //&lt;debug&gt;
  958. newUpdater.displayName = className + '#' + updaterName;
  959. //&lt;/debug&gt;
  960. this[updaterName] = newUpdater;
  961. }
  962. },
  963. //&lt;/feature&gt;
  964. <span id='Ext-Base-method-destroy'> /**
  965. </span> * @private
  966. */
  967. destroy: function() {
  968. this.destroy = Ext.emptyFn;
  969. }
  970. });
  971. <span id='Ext-Base-method-callOverridden'> /**
  972. </span> * Call the original method that was previously overridden with {@link Ext.Base#override}
  973. *
  974. * Ext.define('My.Cat', {
  975. * constructor: function() {
  976. * alert(&quot;I'm a cat!&quot;);
  977. * }
  978. * });
  979. *
  980. * My.Cat.override({
  981. * constructor: function() {
  982. * alert(&quot;I'm going to be a cat!&quot;);
  983. *
  984. * this.callOverridden();
  985. *
  986. * alert(&quot;Meeeeoooowwww&quot;);
  987. * }
  988. * });
  989. *
  990. * var kitty = new My.Cat(); // alerts &quot;I'm going to be a cat!&quot;
  991. * // alerts &quot;I'm a cat!&quot;
  992. * // alerts &quot;Meeeeoooowwww&quot;
  993. *
  994. * @param {Array/Arguments} args The arguments, either an array or the `arguments` object
  995. * from the current method, for example: `this.callOverridden(arguments)`
  996. * @return {Object} Returns the result of calling the overridden method
  997. * @protected
  998. * @deprecated as of 4.1. Use {@link #callParent} instead.
  999. */
  1000. Base.prototype.callOverridden = Base.prototype.callParent;
  1001. Ext.Base = Base;
  1002. }(Ext.Function.flexSetter));
  1003. </pre>
  1004. </body>
  1005. </html>