]>
git.proxmox.com Git - sencha-touch.git/blob - src/src/core/class/Base.js
7 * @author Jacky Nguyen <jacky@sencha.com>
9 * The root of all classes created with {@link Ext#define}.
11 * Ext.Base is the building block of all Ext classes. All classes in Ext inherit from Ext.Base. All prototype and static
12 * members of this class are inherited by all other classes.
14 * See the [Class System Guide](../../../core_concepts/class_system.html) for more.
17 (function(flexSetter
) {
22 // These static properties will be copied to every newly created class with {@link Ext#define}
24 $className
: 'Ext.Base',
29 * Create a new instance of this Class.
31 * Ext.define('My.cool.Class', {
35 * My.cool.Class.create({
39 * All parameters are passed to the constructor of the class.
41 * @return {Object} the created instance.
46 return Ext
.create
.apply(Ext
, [this].concat(Array
.prototype.slice
.call(arguments
, 0)));
54 extend: function(parent
) {
55 var parentPrototype
= parent
.prototype,
56 prototype, i
, ln
, name
, statics
;
58 prototype = this.prototype = Ext
.Object
.chain(parentPrototype
);
59 prototype.self
= this;
61 this.superclass
= prototype.superclass
= parentPrototype
;
63 if (!parent
.$isClass
) {
64 Ext
.apply(prototype, Ext
.Base
.prototype);
65 prototype.constructor = function() {
66 parentPrototype
.constructor.apply(this, arguments
);
70 //<feature classSystem.inheritableStatics>
71 // Statics inheritance
72 statics
= parentPrototype
.$inheritableStatics
;
75 for (i
= 0,ln
= statics
.length
; i
< ln
; i
++) {
78 if (!this.hasOwnProperty(name
)) {
79 this[name
] = parent
[name
];
85 if (parent
.$onExtended
) {
86 this.$onExtended
= parent
.$onExtended
.slice();
89 //<feature classSystem.config>
90 prototype.config
= prototype.defaultConfig
= new prototype.configClass
;
91 prototype.initConfigList
= prototype.initConfigList
.slice();
92 prototype.initConfigMap
= Ext
.Object
.chain(prototype.initConfigMap
);
108 triggerExtended: function() {
109 var callbacks
= this.$onExtended
,
110 ln
= callbacks
.length
,
114 for (i
= 0; i
< ln
; i
++) {
115 callback
= callbacks
[i
];
116 callback
.fn
.apply(callback
.scope
|| this, arguments
);
126 onExtended: function(fn
, scope
) {
127 this.$onExtended
.push({
140 addConfig: function(config
, fullMerge
) {
141 var prototype = this.prototype,
142 initConfigList
= prototype.initConfigList
,
143 initConfigMap
= prototype.initConfigMap
,
144 defaultConfig
= prototype.defaultConfig
,
145 hasInitConfigItem
, name
, value
;
147 fullMerge
= Boolean(fullMerge
);
149 for (name
in config
) {
150 if (config
.hasOwnProperty(name
) && (fullMerge
|| !(name
in defaultConfig
))) {
151 value
= config
[name
];
152 hasInitConfigItem
= initConfigMap
[name
];
154 if (value
!== null) {
155 if (!hasInitConfigItem
) {
156 initConfigMap
[name
] = true;
157 initConfigList
.push(name
);
160 else if (hasInitConfigItem
) {
161 initConfigMap
[name
] = false;
162 Ext
.Array
.remove(initConfigList
, name
);
168 Ext
.merge(defaultConfig
, config
);
171 Ext
.mergeIf(defaultConfig
, config
);
174 prototype.configClass
= Ext
.Object
.classify(defaultConfig
);
178 * Add / override static properties of this class.
180 * Ext.define('My.cool.Class', {
184 * My.cool.Class.addStatics({
185 * someProperty: 'someValue', // My.cool.Class.someProperty = 'someValue'
186 * method1: function() { }, // My.cool.Class.method1 = function() { ... };
187 * method2: function() { } // My.cool.Class.method2 = function() { ... };
190 * @param {Object} members
191 * @return {Ext.Base} this
195 addStatics: function(members
) {
198 var className
= Ext
.getClassName(this);
201 for (name
in members
) {
202 if (members
.hasOwnProperty(name
)) {
203 member
= members
[name
];
205 if (typeof member
== 'function') {
206 member
.displayName
= className
+ '.' + name
;
221 addInheritableStatics: function(members
) {
222 var inheritableStatics
,
223 hasInheritableStatics
,
224 prototype = this.prototype,
227 inheritableStatics
= prototype.$inheritableStatics
;
228 hasInheritableStatics
= prototype.$hasInheritableStatics
;
230 if (!inheritableStatics
) {
231 inheritableStatics
= prototype.$inheritableStatics
= [];
232 hasInheritableStatics
= prototype.$hasInheritableStatics
= {};
236 var className
= Ext
.getClassName(this);
239 for (name
in members
) {
240 if (members
.hasOwnProperty(name
)) {
241 member
= members
[name
];
243 if (typeof member
== 'function') {
244 member
.displayName
= className
+ '.' + name
;
249 if (!hasInheritableStatics
[name
]) {
250 hasInheritableStatics
[name
] = true;
251 inheritableStatics
.push(name
);
260 * Add methods / properties to the prototype of this class.
263 * Ext.define('My.awesome.Cat', {
264 * constructor: function() {
269 * My.awesome.Cat.addMembers({
271 * alert('Meowww...');
275 * var kitty = new My.awesome.Cat();
278 * @param {Object} members
282 addMembers: function(members
) {
283 var prototype = this.prototype,
288 var className
= this.$className
|| '';
291 for (name
in members
) {
292 if (members
.hasOwnProperty(name
)) {
293 member
= members
[name
];
295 if (typeof member
== 'function' && !member
.$isClass
&& member
!== Ext
.emptyFn
) {
296 member
.$owner
= this;
299 member
.displayName
= className
+ '#' + name
;
303 prototype[name
] = member
;
315 addMember: function(name
, member
) {
316 if (typeof member
== 'function' && !member
.$isClass
&& member
!== Ext
.emptyFn
) {
317 member
.$owner
= this;
320 member
.displayName
= (this.$className
|| '') + '#' + name
;
324 this.prototype[name
] = member
;
334 implement: function() {
335 this.addMembers
.apply(this, arguments
);
339 * Borrow another class' members to the prototype of this class.
341 * Ext.define('Bank', {
343 * printMoney: function() {
348 * Ext.define('Thief', {
352 * Thief.borrow(Bank, ['money', 'printMoney']);
354 * var steve = new Thief();
356 * alert(steve.money); // alerts '$$$'
357 * steve.printMoney(); // alerts '$$$$$$$'
359 * @param {Ext.Base} fromClass The class to borrow members from
360 * @param {Array/String} members The names of the members to borrow
361 * @return {Ext.Base} this
366 borrow: function(fromClass
, members
) {
367 var prototype = this.prototype,
368 fromPrototype
= fromClass
.prototype,
370 className
= Ext
.getClassName(this),
372 i
, ln
, name
, fn
, toBorrow
;
374 members
= Ext
.Array
.from(members
);
376 for (i
= 0,ln
= members
.length
; i
< ln
; i
++) {
379 toBorrow
= fromPrototype
[name
];
381 if (typeof toBorrow
== 'function') {
383 return toBorrow
.apply(this, arguments
);
388 fn
.displayName
= className
+ '#' + name
;
395 prototype[name
] = fn
;
398 prototype[name
] = toBorrow
;
406 * Override members of this class. Overridden methods can be invoked via
407 * {@link Ext.Base#callParent}.
409 * Ext.define('My.Cat', {
410 * constructor: function() {
411 * alert("I'm a cat!");
416 * constructor: function() {
417 * alert("I'm going to be a cat!");
419 * var instance = this.callParent(arguments);
421 * alert("Meeeeoooowwww");
427 * var kitty = new My.Cat(); // alerts "I'm going to be a cat!"
428 * // alerts "I'm a cat!"
429 * // alerts "Meeeeoooowwww"
431 * As of 2.1, direct use of this method is deprecated. Use {@link Ext#define Ext.define}
434 * Ext.define('My.CatOverride', {
435 * override: 'My.Cat',
437 * constructor: function() {
438 * alert("I'm going to be a cat!");
440 * var instance = this.callParent(arguments);
442 * alert("Meeeeoooowwww");
448 * The above accomplishes the same result but can be managed by the {@link Ext.Loader}
449 * which can properly order the override and its target class and the build process
450 * can determine whether the override is needed based on the required state of the
451 * target class (My.Cat).
453 * @param {Object} members The properties to add to this class. This should be
454 * specified as an object literal containing one or more properties.
455 * @return {Ext.Base} this class
458 * @deprecated 2.1.0 Please use {@link Ext#define Ext.define} instead
460 override: function(members
) {
462 enumerables
= Ext
.enumerables
,
463 target
= me
.prototype,
464 cloneFunction
= Ext
.Function
.clone
,
465 currentConfig
= target
.config
,
466 name
, index
, member
, statics
, names
, previous
, newConfig
, prop
;
468 if (arguments
.length
=== 2) {
471 members
[name
] = arguments
[1];
476 names
= []; // clean slate for prototype (1st pass) and static (2nd pass)
477 statics
= null; // not needed 1st pass, but needs to be cleared for 2nd pass
479 for (name
in members
) { // hasOwnProperty is checked in the next loop...
480 if (name
== 'statics') {
481 statics
= members
[name
];
483 else if (name
== 'config') {
484 newConfig
= members
[name
];
486 for (prop
in newConfig
) {
487 if (!(prop
in currentConfig
)) {
488 throw new Error("Attempting to override a non-existant config property. This is not " +
489 "supported, you must extend the Class.");
493 me
.addConfig(newConfig
, true);
501 names
.push
.apply(names
, enumerables
);
504 for (index
= names
.length
; index
--; ) {
507 if (members
.hasOwnProperty(name
)) {
508 member
= members
[name
];
510 if (typeof member
== 'function' && !member
.$className
&& member
!== Ext
.emptyFn
) {
511 if (typeof member
.$owner
!= 'undefined') {
512 member
= cloneFunction(member
);
516 var className
= me
.$className
;
518 member
.displayName
= className
+ '#' + name
;
525 previous
= target
[name
];
527 member
.$previous
= previous
;
531 target
[name
] = member
;
535 target
= me
; // 2nd pass is for statics
536 members
= statics
; // statics will be null on 2nd pass
547 callParent: function(args
) {
550 // This code is intentionally inlined for the least amount of debugger stepping
551 return (method
= this.callParent
.caller
) && (method
.$previous
||
552 ((method
= method
.$owner
? method
: method
.caller
) &&
553 method
.$owner
.superclass
.$class[method
.$name
])).apply(this, args
|| noArgs
);
556 //<feature classSystem.mixins>
558 * Used internally by the mixins pre-processor
563 mixin: function(name
, mixinClass
) {
564 var mixin
= mixinClass
.prototype,
565 prototype = this.prototype,
568 if (typeof mixin
.onClassMixedIn
!= 'undefined') {
569 mixin
.onClassMixedIn
.call(mixinClass
, this);
572 if (!prototype.hasOwnProperty('mixins')) {
573 if ('mixins' in prototype) {
574 prototype.mixins
= Ext
.Object
.chain(prototype.mixins
);
577 prototype.mixins
= {};
582 if (key
=== 'mixins') {
583 Ext
.merge(prototype.mixins
, mixin
[key
]);
585 else if (typeof prototype[key
] == 'undefined' && key
!= 'mixinId' && key
!= 'config') {
586 prototype[key
] = mixin
[key
];
590 //<feature classSystem.config>
591 if ('config' in mixin
) {
592 this.addConfig(mixin
.config
, false);
596 prototype.mixins
[name
] = mixin
;
601 * Get the current class' name in string format.
603 * Ext.define('My.cool.Class', {
604 * constructor: function() {
605 * alert(this.self.getName()); // alerts 'My.cool.Class'
609 * My.cool.Class.getName(); // 'My.cool.Class'
611 * @return {String} className
615 getName: function() {
616 return Ext
.getClassName(this);
620 * Create aliases for existing prototype methods. Example:
622 * Ext.define('My.cool.Class', {
623 * method1: function() { },
624 * method2: function() { }
627 * var test = new My.cool.Class();
629 * My.cool.Class.createAlias({
630 * method3: 'method1',
634 * test.method3(); // test.method1()
636 * My.cool.Class.createAlias('method5', 'method3');
638 * test.method5(); // test.method3() -> test.method1()
640 * @param {String/Object} alias The new method name, or an object to set multiple aliases. See
641 * {@link Ext.Function#flexSetter flexSetter}
642 * @param {String/Object} origin The original method name
647 createAlias
: flexSetter(function(alias
, origin
) {
648 this.override(alias
, function() {
649 return this[origin
].apply(this, arguments
);
658 addXtype: function(xtype
) {
659 var prototype = this.prototype,
660 xtypesMap
= prototype.xtypesMap
,
661 xtypes
= prototype.xtypes
,
662 xtypesChain
= prototype.xtypesChain
;
664 if (!prototype.hasOwnProperty('xtypesMap')) {
665 xtypesMap
= prototype.xtypesMap
= Ext
.merge({}, prototype.xtypesMap
|| {});
666 xtypes
= prototype.xtypes
= prototype.xtypes
? [].concat(prototype.xtypes
) : [];
667 xtypesChain
= prototype.xtypesChain
= prototype.xtypesChain
? [].concat(prototype.xtypesChain
) : [];
668 prototype.xtype
= xtype
;
671 if (!xtypesMap
[xtype
]) {
672 xtypesMap
[xtype
] = true;
674 xtypesChain
.push(xtype
);
675 Ext
.ClassManager
.setAlias(this, 'widget.' + xtype
);
685 $className
: 'Ext.Base',
687 configClass
: Ext
.emptyFn
,
694 * Get the reference to the class from which this object was instantiated. Note that unlike {@link Ext.Base#self},
695 * `this.statics()` is scope-independent and it always returns the class from which it was called, regardless of what
696 * `this` points to during run-time
698 * Ext.define('My.Cat', {
701 * speciesName: 'Cat' // My.Cat.speciesName = 'Cat'
704 * constructor: function() {
705 * var statics = this.statics();
707 * alert(statics.speciesName); // always equals to 'Cat' no matter what 'this' refers to
708 * // equivalent to: My.Cat.speciesName
710 * alert(this.self.speciesName); // dependent on 'this'
712 * statics.totalCreated++;
715 * clone: function() {
716 * var cloned = new this.self(); // dependent on 'this'
718 * cloned.groupName = this.statics().speciesName; // equivalent to: My.Cat.speciesName
725 * Ext.define('My.SnowLeopard', {
729 * speciesName: 'Snow Leopard' // My.SnowLeopard.speciesName = 'Snow Leopard'
732 * constructor: function() {
737 * var cat = new My.Cat(); // alerts 'Cat', then alerts 'Cat'
739 * var snowLeopard = new My.SnowLeopard(); // alerts 'Cat', then alerts 'Snow Leopard'
741 * var clone = snowLeopard.clone();
742 * alert(Ext.getClassName(clone)); // alerts 'My.SnowLeopard'
743 * alert(clone.groupName); // alerts 'Cat'
745 * alert(My.Cat.totalCreated); // alerts 3
748 * @return {Ext.Class}
750 statics: function() {
751 var method
= this.statics
.caller
,
758 return method
.$owner
;
762 * Call the "parent" method of the current method. That is the method previously
763 * overridden by derivation or by an override (see {@link Ext#define}).
765 * Ext.define('My.Base', {
766 * constructor: function (x) {
771 * method: function (x) {
777 * Ext.define('My.Derived', {
780 * constructor: function () {
781 * this.callParent([21]);
785 * var obj = new My.Derived();
787 * alert(obj.x); // alerts 21
789 * This can be used with an override as follows:
791 * Ext.define('My.DerivedOverride', {
792 * override: 'My.Derived',
794 * constructor: function (x) {
795 * this.callParent([x*2]); // calls original My.Derived constructor
799 * var obj = new My.Derived();
801 * alert(obj.x); // now alerts 42
803 * This also works with static methods.
805 * Ext.define('My.Derived2', {
809 * method: function (x) {
810 * return this.callParent([x*2]); // calls My.Base.method
815 * alert(My.Base.method(10)); // alerts 10
816 * alert(My.Derived2.method(10)); // alerts 20
818 * Lastly, it also works with overridden static methods.
820 * Ext.define('My.Derived2Override', {
821 * override: 'My.Derived2',
824 * method: function (x) {
825 * return this.callParent([x*2]); // calls My.Derived2.method
830 * alert(My.Derived2.method(10)); // now alerts 40
832 * To override a method and replace it and also call the superclass method, use
833 * {@link #callSuper}. This is often done to patch a method to fix a bug.
836 * @param {Array/Arguments} args The arguments, either an array or the `arguments` object
837 * from the current method, for example: `this.callParent(arguments)`
838 * @return {Object} Returns the result of calling the parent method
840 callParent: function(args
) {
841 // NOTE: this code is deliberately as few expressions (and no function calls)
842 // as possible so that a debugger can skip over this noise with the minimum number
843 // of steps. Basically, just hit Step Into until you are where you really wanted
846 superMethod
= (method
= this.callParent
.caller
) && (method
.$previous
||
847 ((method
= method
.$owner
? method
: method
.caller
) &&
848 method
.$owner
.superclass
[method
.$name
]));
852 method
= this.callParent
.caller
;
853 var parentClass
, methodName
;
855 if (!method
.$owner
) {
856 if (!method
.caller
) {
857 throw new Error("Attempting to call a protected method from the public scope, which is not allowed");
860 method
= method
.caller
;
863 parentClass
= method
.$owner
.superclass
;
864 methodName
= method
.$name
;
866 if (!(methodName
in parentClass
)) {
867 throw new Error("this.callParent() was called but there's no such method (" + methodName
+
868 ") found in the parent class (" + (Ext
.getClassName(parentClass
) || 'Object') + ")");
873 return superMethod
.apply(this, args
|| noArgs
);
877 * This method is used by an override to call the superclass method but bypass any
878 * overridden method. This is often done to "patch" a method that contains a bug
879 * but for whatever reason cannot be fixed directly.
883 * Ext.define('Ext.some.Class', {
884 * method: function () {
885 * console.log('Good');
889 * Ext.define('Ext.some.DerivedClass', {
890 * method: function () {
891 * console.log('Bad');
893 * // ... logic but with a bug ...
899 * To patch the bug in `DerivedClass.method`, the typical solution is to create an
902 * Ext.define('App.paches.DerivedClass', {
903 * override: 'Ext.some.DerivedClass',
905 * method: function () {
906 * console.log('Fixed');
908 * // ... logic but with bug fixed ...
914 * The patch method cannot use `callParent` to call the superclass `method` since
915 * that would call the overridden method containing the bug. In other words, the
916 * above patch would only produce "Fixed" then "Good" in the console log, whereas,
917 * using `callParent` would produce "Fixed" then "Bad" then "Good".
920 * @param {Array/Arguments} args The arguments, either an array or the `arguments` object
921 * from the current method, for example: `this.callSuper(arguments)`
922 * @return {Object} Returns the result of calling the superclass method
924 callSuper: function(args
) {
926 superMethod
= (method
= this.callSuper
.caller
) && ((method
= method
.$owner
? method
: method
.caller
) &&
927 method
.$owner
.superclass
[method
.$name
]);
931 method
= this.callSuper
.caller
;
932 var parentClass
, methodName
;
934 if (!method
.$owner
) {
935 if (!method
.caller
) {
936 throw new Error("Attempting to call a protected method from the public scope, which is not allowed");
939 method
= method
.caller
;
942 parentClass
= method
.$owner
.superclass
;
943 methodName
= method
.$name
;
945 if (!(methodName
in parentClass
)) {
946 throw new Error("this.callSuper() was called but there's no such method (" + methodName
+
947 ") found in the parent class (" + (Ext
.getClassName(parentClass
) || 'Object') + ")");
952 return superMethod
.apply(this, args
|| noArgs
);
956 * Call the original method that was previously overridden with {@link Ext.Base#override},
958 * This method is deprecated as {@link #callParent} does the same thing.
960 * Ext.define('My.Cat', {
961 * constructor: function() {
962 * alert("I'm a cat!");
967 * constructor: function() {
968 * alert("I'm going to be a cat!");
970 * var instance = this.callOverridden();
972 * alert("Meeeeoooowwww");
978 * var kitty = new My.Cat(); // alerts "I'm going to be a cat!"
979 * // alerts "I'm a cat!"
980 * // alerts "Meeeeoooowwww"
982 * @param {Array/Arguments} args The arguments, either an array or the `arguments` object
983 * from the current method, for example: `this.callOverridden(arguments)`
984 * @return {Object} Returns the result of calling the overridden method
987 callOverridden: function(args
) {
988 var method
= this.callOverridden
.caller
;
989 return method
&& method
.$previous
.apply(this, args
|| noArgs
);
993 * @property {Ext.Class} self
995 * Get the reference to the current class from which this object was instantiated. Unlike {@link Ext.Base#statics},
996 * `this.self` is scope-dependent and it's meant to be used for dynamic inheritance. See {@link Ext.Base#statics}
997 * for a detailed comparison
999 * Ext.define('My.Cat', {
1001 * speciesName: 'Cat' // My.Cat.speciesName = 'Cat'
1004 * constructor: function() {
1005 * alert(this.self.speciesName); // dependent on 'this'
1008 * clone: function() {
1009 * return new this.self();
1014 * Ext.define('My.SnowLeopard', {
1017 * speciesName: 'Snow Leopard' // My.SnowLeopard.speciesName = 'Snow Leopard'
1021 * var cat = new My.Cat(); // alerts 'Cat'
1022 * var snowLeopard = new My.SnowLeopard(); // alerts 'Snow Leopard'
1024 * var clone = snowLeopard.clone();
1025 * alert(Ext.getClassName(clone)); // alerts 'My.SnowLeopard'
1031 // Default constructor, simply returns `this`
1032 constructor: function() {
1036 //<feature classSystem.config>
1038 wasInstantiated
: false,
1041 * Initialize configuration for this class. a typical example:
1043 * Ext.define('My.awesome.Class', {
1044 * // The default config
1050 * constructor: function(config) {
1051 * this.initConfig(config);
1055 * var awesome = new My.awesome.Class({
1056 * name: 'Super Awesome'
1059 * alert(awesome.getName()); // 'Super Awesome'
1062 * @param {Object} instanceConfig
1063 * @return {Object} mixins The mixin prototypes as key - value pairs
1065 initConfig: function(instanceConfig
) {
1067 // if (instanceConfig && instanceConfig.breakOnInitConfig) {
1071 var configNameCache
= Ext
.Class
.configNameCache
,
1072 prototype = this.self
.prototype,
1073 initConfigList
= this.initConfigList
,
1074 initConfigMap
= this.initConfigMap
,
1075 config
= new this.configClass
,
1076 defaultConfig
= this.defaultConfig
,
1077 i
, ln
, name
, value
, nameMap
, getName
;
1079 this.initConfig
= Ext
.emptyFn
;
1081 this.initialConfig
= instanceConfig
|| {};
1083 if (instanceConfig
) {
1084 Ext
.merge(config
, instanceConfig
);
1087 this.config
= config
;
1089 // Optimize initConfigList *once* per class based on the existence of apply* and update* methods
1090 // Happens only once during the first instantiation
1091 if (!prototype.hasOwnProperty('wasInstantiated')) {
1092 prototype.wasInstantiated
= true;
1094 for (i
= 0,ln
= initConfigList
.length
; i
< ln
; i
++) {
1095 name
= initConfigList
[i
];
1096 nameMap
= configNameCache
[name
];
1097 value
= defaultConfig
[name
];
1099 if (!(nameMap
.apply
in prototype)
1100 && !(nameMap
.update
in prototype)
1101 && prototype[nameMap
.set].$isDefault
1102 && typeof value
!= 'object') {
1103 prototype[nameMap
.internal] = defaultConfig
[name
];
1104 initConfigMap
[name
] = false;
1105 Ext
.Array
.remove(initConfigList
, name
);
1112 if (instanceConfig
) {
1113 initConfigList
= initConfigList
.slice();
1115 for (name
in instanceConfig
) {
1116 if (name
in defaultConfig
&& !initConfigMap
[name
]) {
1117 initConfigList
.push(name
);
1122 // Point all getters to the initGetters
1123 for (i
= 0,ln
= initConfigList
.length
; i
< ln
; i
++) {
1124 name
= initConfigList
[i
];
1125 nameMap
= configNameCache
[name
];
1126 this[nameMap
.get] = this[nameMap
.initGet
];
1129 this.beforeInitConfig(config
);
1131 for (i
= 0,ln
= initConfigList
.length
; i
< ln
; i
++) {
1132 name
= initConfigList
[i
];
1133 nameMap
= configNameCache
[name
];
1134 getName
= nameMap
.get;
1136 if (this.hasOwnProperty(getName
)) {
1137 this[nameMap
.set].call(this, config
[name
]);
1138 delete this[getName
];
1145 beforeInitConfig
: Ext
.emptyFn
,
1150 getCurrentConfig: function() {
1151 var defaultConfig
= this.defaultConfig
,
1152 configNameCache
= Ext
.Class
.configNameCache
,
1156 for (name
in defaultConfig
) {
1157 nameMap
= configNameCache
[name
];
1158 config
[name
] = this[nameMap
.get].call(this);
1167 setConfig: function(config
, applyIfNotSet
) {
1172 var configNameCache
= Ext
.Class
.configNameCache
,
1173 currentConfig
= this.config
,
1174 defaultConfig
= this.defaultConfig
,
1175 initialConfig
= this.initialConfig
,
1177 name
, i
, ln
, nameMap
;
1179 applyIfNotSet
= Boolean(applyIfNotSet
);
1181 for (name
in config
) {
1182 if ((applyIfNotSet
&& (name
in initialConfig
))) {
1186 currentConfig
[name
] = config
[name
];
1188 if (name
in defaultConfig
) {
1189 configList
.push(name
);
1190 nameMap
= configNameCache
[name
];
1191 this[nameMap
.get] = this[nameMap
.initGet
];
1195 for (i
= 0,ln
= configList
.length
; i
< ln
; i
++) {
1196 name
= configList
[i
];
1197 nameMap
= configNameCache
[name
];
1198 this[nameMap
.set].call(this, config
[name
]);
1199 delete this[nameMap
.get];
1205 set: function(name
, value
) {
1206 return this[Ext
.Class
.configNameCache
[name
].set].call(this, value
);
1209 get: function(name
) {
1210 return this[Ext
.Class
.configNameCache
[name
].get].call(this);
1216 getConfig: function(name
) {
1217 return this[Ext
.Class
.configNameCache
[name
].get].call(this);
1223 hasConfig: function(name
) {
1224 return (name
in this.defaultConfig
);
1228 * Returns the initial configuration passed to constructor.
1230 * @param {String} [name] When supplied, value for particular configuration
1231 * option is returned, otherwise the full config object is returned.
1232 * @return {Object/Mixed}
1234 getInitialConfig: function(name
) {
1235 var config
= this.config
;
1241 return config
[name
];
1248 onConfigUpdate: function(names
, callback
, scope
) {
1249 var self
= this.self
,
1251 className
= self
.$className
,
1254 updaterName
, updater
, newUpdater
;
1256 names
= Ext
.Array
.from(names
);
1258 scope
= scope
|| this;
1260 for (i
= 0,ln
= names
.length
; i
< ln
; i
++) {
1262 updaterName
= 'update' + Ext
.String
.capitalize(name
);
1263 updater
= this[updaterName
] || Ext
.emptyFn
;
1264 newUpdater = function() {
1265 updater
.apply(this, arguments
);
1266 scope
[callback
].apply(scope
, arguments
);
1268 newUpdater
.$name
= updaterName
;
1269 newUpdater
.$owner
= self
;
1271 newUpdater
.displayName
= className
+ '#' + updaterName
;
1274 this[updaterName
] = newUpdater
;
1281 * @param {String} name
1282 * @param {Mixed} value
1285 link: function(name
, value
) {
1287 this.link
= this.doLink
;
1288 return this.link
.apply(this, arguments
);
1291 doLink: function(name
, value
) {
1292 this.$links
[name
] = true;
1302 unlink: function() {
1303 var i
, ln
, link
, value
;
1305 for (i
= 0, ln
= arguments
.length
; i
< ln
; i
++) {
1306 link
= arguments
[i
];
1307 if (this.hasOwnProperty(link
)) {
1310 if (value
.isInstance
&& !value
.isDestroyed
) {
1313 else if (value
.parentNode
&& 'nodeType' in value
) {
1314 value
.parentNode
.removeChild(value
);
1327 destroy: function() {
1328 this.destroy
= Ext
.emptyFn
;
1329 this.isDestroyed
= true;
1331 if (this.hasOwnProperty('$links')) {
1332 this.unlink
.apply(this, Ext
.Object
.getKeys(this.$links
));
1340 })(Ext
.Function
.flexSetter
);