View Full Version : Confused on why Architect uses initComponent for some and not other attributes

25 Jul 2013, 11:34 AM
SA made the following code. I'm confused why some (and not all or none) of the class properties are set using initComponent and others are set first. Does it have to do with wanting to use the this pointer on some and not others? what is the "rule" for when to set in initComponent adn when to set outside.

Ext.define('MyApp.view.MyGridPanel', {
extend: 'Ext.grid.Panel',
alias: 'widget.mygridpanel',

height: 250,
width: 400,
title: 'My Grid Panel',
store: 'TagStore',

initComponent: function() {
var me = this;

Ext.applyIf(me, {
columns: [
xtype: 'gridcolumn',
dataIndex: 'id',
text: 'Id'
xtype: 'gridcolumn',
dataIndex: 'tagName',
text: 'TagName'



25 Jul 2013, 12:49 PM
Simple types like strings, numbers and booleans go at the top and will be put on the prototype of the class.

Complex types like arrays, objects and instances of classes (objects) will go into the component and will be put on the instance of this particular class.

If the complex types were put on the prototype they would be shared across instances of the class. (Bad things!) Also initComponent is used to setup event handlers so that it can have a reference to the current "this" object (which it would not have at definition time).

25 Jul 2013, 1:23 PM
thanks. that's what I was looking for.