lundi 28 septembre 2015

Load particular methods from module. Design patterns

I've recently started to use RequireJS, which enables me to organize my code in a nice way. So, define and require became my best friends. But now I see one problem, which I do not know how to solve in terms of RequireJS, or in terms of some particular Design Pattern. So, imagine, I have a really huge module containing zillions of methods. I define it like so:

define(function(BIG_MODULE){
    return {
        property_0: "value_0",
        property_1: "value_1",
        ....
        property_zillion: "value_zillion",
        method_0: function(){...},
        ...
        method_zillion: function(){...}
    }
});

Please, do not ask me, why I have such a huge module - it's just an abstraction. And, so, the question now is - if it is possible to import or require not the entire module, but some of its properties and methods? Lets say I somehow assigned my module to some local instance and if I investigate the internals of this instance, then I can see, that it contains only some particular properties and methods. Is it possible?

Aucun commentaire:

Enregistrer un commentaire