Created
May 17, 2014 06:09
-
-
Save IrakliJani/3bc4b138906cf3d5a020 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 DI = function (dependency) { | |
| this.dependency = dependency; | |
| }; | |
| DI.prototype.inject = function (func) { | |
| var $scope = func | |
| .toString() | |
| .match(/function *\((.*)\)/)[1] | |
| .split(',') | |
| .map(function (e) { return e.trim(); }) | |
| .filter(function (e) { return /^[$\w]+$/.test(e); }) | |
| .map(function (d) { return this.dependency[d]; }, this); | |
| return function () { | |
| return func.apply(null, $scope); | |
| }; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment