ts84zs
asked on
understand js code
I am trying to understand this javascript code.. I have a .js file and code is below...
In this section of the code,
return declare([BaseWidget], {
why is BaseWidget written within square bracket?
Whole Code :
pl help
thanks
In this section of the code,
return declare([BaseWidget], {
why is BaseWidget written within square bracket?
Whole Code :
define(['dojo/_base/declare', 'jimu/BaseWidget'],
function(declare, BaseWidget) {
//To create a widget, you need to derive from BaseWidget.
return declare([BaseWidget], {
// DemoWidget code goes here
//please note that this property is be set by the framework when widget is loaded.
//templateString: template,
baseClass: 'jimu-widget-demo',
name: 'Demo',
postCreate: function() {
this.inherited(arguments);
console.log('postCreate');
},
onSignOut: function(){
console.log('onSignOut');
}
});
});
pl help
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Leaving the square brackets out would fail if the function expects an array and loops over them
Leaving the square brackets out would fail if the function expects an array and loops over themIf you refer to the documentation in my previous post it says.
superclass null|Object|Object[]
This parameter is either
null (no base class),
an object (a base class) or
an array of objects (multiple inheritance).
Which implies if it is a single object it does not require brackets - but if brackets are included it will still process it as an array is also an option.
Ah, ok, then it is cleverer than I thought
ASKER
thanks so much i am looking into it...
that is how to coerce BaseWidget into the array