PDA

View Full Version : Application - EventBus instance



LesJ
27 Jun 2012, 12:31 PM
This is really a basic JavaScript question... :-/

...we are creating an instance of EventBus... why there are no enclosing parenthesis () after EventBus?

See how me.controllers is assigned an instance of MixedCollection... there are parens () after MixedCollection...


Ext.define('Ext.app.Application', {
....
constructor: function(config) {
...
me.eventbus = new Ext.app.EventBus; // why not new Ext.app.EventBus();


controllers = Ext.Array.from(me.controllers);
ln = controllers && controllers.length;


me.controllers = new Ext.util.MixedCollection();
....

scottmartin
27 Jun 2012, 7:36 PM
When using the new operator, this is just a preference ...
It should be updated to maintain consistent code.

Both are equal:


var evb = new Ext.app.EventBus;
var evb = new Ext.app.EventBus();


In the following, they are different:


var evb = eventBus; // assign function to var
var evb = eventBus(); // function is executed and assigns return value


Regards,
Scott.