Return Value of Function as items Pattern

Code in this post can be obsolete, however, principles and theory may still apply.
    var items = [];

    // populate items array

    return items;
Follow me:
Latest posts by saki (see all)

6 Responses

  1. I’m trying to use this method to attache dynamicly a parameter to a proxy in a model.

    proxy : {
    extraParams : {
    test : (function(){
    return ‘test’;

    This cause an error : Uncaught TypeError: undefined is not a function
    Where am I wrong ?

  2. 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 .

  3. A good example on how to use this pattern:

         xtype: 'combo'
        ,fieldLabel: 'Combobox field label'
        ,typeAhead: true
        ,displayField: 'value'
        ,mode: 'local'
        ,value: new Date().format('Y')
        ,triggerAction: 'all'
        ,emptyText:'Select year...'
        ,store: (function(){
            var years = [];         
            var dt = new Date();
            for(var i=1900; i <= dt.format('Y'); i++){
            return years;

    That code will render a combobox for selecting one year between 1900 and the current year, basically an “year selector”.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Enter your username and password to log into your account. Don't have an account? Sign up.

Want to collaborate on an upcoming project?