Created
August 21, 2014 17:44
-
-
Save j03m/fab2d946c6d5ffea163f to your computer and use it in GitHub Desktop.
dependency injection with dynamic scoping
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
var MyClass = require("./classScope1.js"); | |
function setter(name, value){ | |
eval(name+"=value"); | |
} | |
MyClass.injectSetter(String(setter)); | |
MyClass.setter('fs', {}); | |
var myclass = new MyClass(); | |
myclass.go2(); | |
//***************classScope1.js | |
var fs = require('fs'); | |
var MyClass = function(){ | |
this.value = 1; | |
}; | |
MyClass.prototype.go = function(){ | |
console.log("hihihihi:", this.value); | |
}; | |
MyClass.prototype.go2 = function(){ | |
console.log(fs); | |
}; | |
MyClass.injectSetter = function(fn){ | |
eval("MyClass.setter=" + fn); | |
}; | |
module.exports = MyClass; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment