Injection

by gschutz

JavaScript

function Builder() {
    var svg = "private!";
    
    this.name = "Big Treta";
    
    // supose here we need an external resource;
    // like this.wall = Wall;
    // but we want that Wall be injected with this scope variables.
        
    var wall = function() {
        return new Wall();
    };
    
    
    this.get = function() {
        return this.name;
    };
}


function Wall() {
    console.log(svg);
    
    this.name = "O muro";
}

(function(exports) {
    'use strict';
    function Inject() {
        'use strict';
        var one = 1;
        var two = 2;
        
        window.one = 1;
        
        this.vai = "vaai";
    }
    
    exports.Inject = Inject;
})(window);

console.log(new Inject());
console.log(window.one);