Skip to content

Instantly share code, notes, and snippets.

@IrakliJani
Created May 17, 2014 06:09
Show Gist options
  • Select an option

  • Save IrakliJani/3bc4b138906cf3d5a020 to your computer and use it in GitHub Desktop.

Select an option

Save IrakliJani/3bc4b138906cf3d5a020 to your computer and use it in GitHub Desktop.
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