0

I started using the revealing pattern and I'm starting to think if there isn't a better approach for this.....

    var grid= (function(){

    var grid='';

   function init(gridOptions) {

     cacheDom(gridOptions);

     //this.bindEvents();
     buildGrid(gridOptions);

    }

    function cacheDom(options) {
       $greeder = $(options.selector);
       /* this.$button = this.$el.find('button');
        this.$input = this.$el.find('input');
        this.$ul = this.$el.find('ul');
        this.template = this.$el.find('#people-template').html();*/
    } 

    function bindEvents() {

    }

    function buildGrid(options){

     $.ajax({
            method: "POST",
            url: options.data,
            data: $.param(options.parameters),
            success: function(data) {

                alert(data);

                // generateGrid(data, options); 
               // styleGrid(options);  //it can be default with bootstrap if the property style is undefined, if the user wants to put his own style he can use style:'custom' parameter
               // generatePager(options);
               // renderGrid(options);

            }
        });

    }

    function generateGrid(data, options){

    } 

    function styleGrid(options){

    }    

    function renderGrid() {

    }



    return {
        init: init
    };

})();
/* dataType: 'array', 'json', 'xml' possible values*/
grid.init({
    title:'The grid',
    selector:'#greeder',
    data:'./api/getCustomers.php',
    parameters: {"id_customer":"32"},
    fields:{
        id_customer:{
         title:'ID customer'
        },
        first_name:{
         title:'First Name' 
        },
        last_name:{
         title:'Last Name'  
        }       
    }   
});

My main question is how could I do in the future if I want to inherit all the methods and properties to a subclass with my current approach.....I wonder if using something similar to some of the prototypal inheritance I saw is a better approach to extend functionality in the future.

enter image description here

You can see in the commented code how a musician add functionality on top of the human class really easily. My question is, which one of the two is better for this situation?......Which of the two gives me the best flexibility to add functionality in the future without code repetition?. I always prefer OOP over other paradigms, but it's nice to know what is best on each situation. Thank you very much.

John
  • 1,711
  • 2
  • 29
  • 42
  • 1
    How about ES2015 classes? It's year 2016 outside. – zerkms May 23 '16 at 01:00
  • I don't see how a (revealing) module pattern gives you *any* flexibility or extensibility. Also, you seem to want to be able to create multiple grid *instances* for different selectors, instead of having one static page-wide gird. – Bergi May 23 '16 at 01:12
  • yes to both. I will check out the advantages of using ES2015 classes ......... @Bergi Of course, I want to create multiple grids for different selectors......But I want different types of grids as well, and that's why I'm thinking of different types of classes....I think I could do it with dependency injection as well, but that's not the question here, I'm just asking a "which is the optimal pattern on this scenario" question...... – John May 23 '16 at 01:28
  • 1
    @Juan: Yes, you want classes. Whether ES6 or ES5 syntax doesn't matter, you can do inheritance, mixins and whatever else. – Bergi May 23 '16 at 01:30
  • Thanks, I will refactor everything using ES6 and use a proper Class, I've been reading that I can declare classes properly with the new standard, so it's definitely the way to go.....Could you post it as an answer so I can accept your answer?....Thanks for the info! – John May 23 '16 at 13:24

0 Answers0