This project is read-only.

Module Local Variables - Useful for Dependency Injection

Topics: General, Language Specification
Nov 9, 2012 at 9:31 PM
Edited Nov 9, 2012 at 9:31 PM

You can already define variables in functions without exporting them. In JavaScript, I very frequently want to create a "module" with local variables that get passed in to it. 

function TestModule(Test, SomeDependency) {
    function hello(name) {
        return "Hello " + name;
    Test.hello = hello;

var testModule = TestModule({}, SomeDependency)

Normally I wouldn't call the function right away, like the above, I would keep the module definition around so I could call it with specific dependencies later. 

Are there any plans to support this pattern? What do you think?