Created
August 21, 2014 14:30
-
-
Save j03m/8bf0d088e586a2976661 to your computer and use it in GitHub Desktop.
Dependency injection sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//global space | |
var MockDepedency = function(){} | |
MockDepedency.prototype.getValue = function(){ | |
console.log("What what what what!!!"); | |
} | |
function __setter(name){ | |
"use strict"; | |
eval(name + "=MockDepedency"); | |
} | |
function evalString(){ | |
eval(__setter); | |
return __setter; | |
} | |
function define(args, callback){ | |
var Dependency = function(){ | |
this.value = 1; | |
} | |
Dependency.prototype.getValue = function(){ | |
console.log(this.value); | |
} | |
return callback(Dependency); | |
} | |
//module space | |
function main (){ | |
var Thing = define([], function(Dependency){ | |
var ThingDef = function(){ | |
this.dep = new Dependency(); | |
}; | |
ThingDef.prototype.doSomething = function(){ | |
this.dep.getValue(); | |
}; | |
eval(String(__setter)); //Would like to get rid of this | |
ThingDef.__setter = __setter; | |
return ThingDef; | |
}); | |
Thing.__setter('Dependency'); | |
var thing = new Thing(); | |
thing.doSomething(); | |
} | |
//app space | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment