Search code examples
javascriptextjsextjs4

obj.get function fails if constructor is defined in ExtJs Class prototype


I am super new to ExtJs world and started with ExtJs 4 and using book "Learning extJs 4"

Here is code snippet i am playing with


Ext.define("MyApp.Category",{
height : 40,
extend : "Ext.data.Model",
fields : [ 
    "id",
    "name",
    "description"
],

constructor : function(config){
    console.log("Config Dump \n");
    console.dir(this);
    //Ext.apply(this, config);
}



});


var category = Ext.create("MyApp.Category",{
id : 1,
name : "Entertainment",
description : "Expenses to have some fun"
});

console.log("this is after instantiation..");
console.debug(category);

console.log(category.get("name"));  
// above line fails gives error - Uncaught TypeError:    Cannot read property 'name' of undefined 
// but if we remove construction defination from class prototype , .get function works very well
console.log(category.get("description"));

Could you please help me to understand whts going here



Solution

  • You must call parent constructor. Add this.callParent(arguments) to the constructor override.