Code in this post can be obsolete, however, principles and theory may still apply.
,items:(function(){ var items = []; // populate items array return items; }).createDelegate(this)()
I'm a well seasoned developer, consultant and educator of web applications based mainly on Sencha libraries, PHP, MySQL and Node.js. Besides (Apple) computers, I love photography and mountain biking.
Follow me:
Latest posts by saki (see all)
- Ext, Angular, React, and Vue - 27. June 2019
- The Site Resurgence - 11. February 2018
- Configuring ViewModel Hierarchy - 19. June 2015
6 Responses
I’m trying to use this method to attache dynamicly a parameter to a proxy in a model.
proxy : {
extraParams : {
test : (function(){
return ‘test’;
}).createDelegate(this)()
},
….
This cause an error : Uncaught TypeError: undefined is not a function
Where am I wrong ?
createDelegate? This function has been removed in Ext 4. Now you would use something like this:
the difference is scope : in case you need to refer to properties/methods of the class itself (`this`) inside the function.
also, i think it’s a good practice to NOT use inline functions (closures) this way, but to refer to defined methods of the class, or to ‘helper’ methods.
correct me if i’m wrong .
I don’t understand what the difference is with
items:function()
{
var items[];
.
.
.
return items;
}()
@Lucian
Exactly! I see that you grasped it fully. You can use same pattern also for items array if you need to.
A good example on how to use this pattern:
That code will render a combobox for selecting one year between 1900 and the current year, basically an “year selector”.