How about this programming style in javascript?

    var RootComponent = {

        init: function(options){
            options = jQuery.extend({name: 'Root'}, options);

            this.run('ContainerComponent.init')(options);
        }

     }

A new method called "run" is then applied to this. And this will launch the method found in the path with this context. Now, what problems do you think I can have? thank

        klass.run = function(path){
                var that = this;
                return function(){
                 // here will be calculated the path, based on the input, this is just an hard coded example...
                    that.sb.klasses['ContainerComponent']['init'].apply(that, arguments);
                }
        }
+3
source share
1 answer

Are you going to use this to change only the objects you control? If you use this on an object that someone else can provide, you will redefine their possible implementation run.

In any case, you can override their implementation run, but then you can break their code.

, run , , , , ( , .)

, . , , , . - , . , , .

+1

Source: https://habr.com/ru/post/1786067/


All Articles