vendredi 4 novembre 2016

What is this anti-pattern called (using parent scopes to pass state)?

I'm trying to describe to a colleague issues I have with how their code is structured, and I'm looking for the name of the anti-pattern he's implemented (bonus points for the software principals it violates). I'm using JS to demonstrate, but this isn't JS specific.

function x() {

    var a, b, c;

    var doWork = function(){
        a = 1;
        b = 2;
        addAB();
        return c;
    };

    var addAB = function(){
        c = a + b;
    };

    var result = doWork();
}

He's passing information into and out of functions/methods using the parent scope. It makes understanding the code very difficult.

Aucun commentaire:

Enregistrer un commentaire