Search code examples
extjssquare-bracket

extJS - when-to & when-not to use square brackets


i have been learning extJS, and i could cram it up but i want to understand...

in the following cases we use square brackets, if not it gives error

require     : ['Ext.container.Viewport']
controllers : ['Users','List']

but in these we don't

Ext.define('myapplication.controller.Mycontroller',{.....
xtype  : 'panel'
extend : 'Ext.app.Controller'

Solution

  • Square brackets means that it's an array (basic javascript). Your require array only contains 1 item now, but it can contain more items. Your controllers is an array of 2 items.

    In your define example xtype doesn't expect an array but a string. Same with extend, you can only extend from one component.

    This info can be found in the docs of ExtJS aswell. For example the controllers config from your example above:

    http://docs.sencha.com/ext-js/4-1/#!/api/Ext.app.Application-cfg-controllers

    The docs mention this controllers : String[]. Which means it expects an array of strings.