Dojo

postCreate and startup function

Hi,

I am new to dojo library, I am came a cross two functions in many dojo code examples : postCreate () and startup(), I did google and gone through dojo documentation but still getting difficult to understand these two functions. Can someone explain in lucid way with example.

startup is used when the widget is placed on the DOM tree (html). We used it to override the CheckBox widget and add a label by default
startup: function () {
domConstruct.create(‘label’, { innerHTML: ‘The Label’, ‘for’: this.get(‘id’)}, this.domNode, ‘after’);
this.inherited(arguments);
}

If you try to do this in postCreate, you will get an error as ‘after’ is unknown at this time.
startup is also used if you have layout widgets like tabs, grids, etc, that need to know their position on the DOM in order to calculate their size. For example, to calculate the 100% width or height. If you created a tab container programmatically in postCreate then in startup you would call
startup: function () {
this.myTab.startup();
this.resize();
}

and in resize function you would call
resize: function(){this.myTab.resize();}

postCreate is generally used for things like creating widgets and html elements and connecting events.