vendredi 29 avril 2016

What javascript design pattern or patterns should I use?

I'm a beginner developer and I am developing medium-large web application, at least to my level, using Yii2 and lot of javascript.

Initially started writting namespace on separate file like:

var NAMESPACE = NAMESPACE || {};

NAMESPACE.components = {
   menu: {
          ...
   },
   forms: {
           .....,
           .....
   }
};

NAMESPACE.prototype = {
    environment: {
       function1: function(){
       },
       function2: .....
    },
    user: {
       function1: function(){
       },
       function2: .....
    },
    actions: {
       function1: function(){
       },
       function2: .....
    }
};

I too have main script file where I created multiple pointers to different parts of the namespace with which I access the components and I make calls to functions. Everything works correctly but the size of the namespace (which already exceeds the 3000 lines) begins to have a tedious growth.

I have read a lot about javascript pattern as modules, prototypes, observers and singletons , but I'm really confused about how I should restructure my code , the type of pattern or patterns that should use.

I wish someone could guide me on this and give me some practical advice. Sorry my poor English. Thanks in advance.

A greeting.

Aucun commentaire:

Enregistrer un commentaire