View Full Version : Am I using the addConfig method correctly?

29 Apr 2014, 12:46 PM
I was expecting the first getMsg call to return "Hi there!", but I see undefined.

Ext.define('MyClass', {
isMyClass: true

var obj = new MyClass();

msg: 'Hi there!'

console.log(obj.getMsg()); // <-- Why undefined?
obj.getMsg(); // <-- "Hello"

1 May 2014, 12:58 AM
There are a couple issues: the MyClass constructor does not call initConfig and the config is added to the class after the instance was created. So even if you fix the first issue the second would bite.

Try this:


1 May 2014, 4:26 AM
I think it's important to note that Ext.Base (which the MyClass above extends) doesn't call initConfig as Don says. This is not true for all classes. For example, Ext.Component does call initConfig in the constructor so any subclass of Ext.Component will call initConfig and therefor you do not have to so it can be important to know what classes do and what classes do not. An easy way to know, look at the source in the inheritance chain to see if a class calls initConfig in the constructor.