Skip to content

Instantly share code, notes, and snippets.

@rafaelvieiras
Last active November 14, 2019 21:09
Show Gist options
  • Save rafaelvieiras/720b6f9c55608c232f6e23ad9ae480ab to your computer and use it in GitHub Desktop.
Save rafaelvieiras/720b6f9c55608c232f6e23ad9ae480ab to your computer and use it in GitHub Desktop.
higher order functions, injeção de depedências no JS como o angular 1
const app = {
allDependencies: {
sayMyNameService: function(name) {
console.warn('Seu nome é ', name);
}
},
controller: function(dependencies, callback) {
const scope = this;
dependencies.forEach(function(dependency) {
if (scope.allDependencies[dependency]) {
scope[dependency] = scope.allDependencies[dependency];
}
});
return function() {
callback.apply(scope, Array.prototype.slice.call(arguments, 0));
}
}
}
app.controller(['sayMyNameService'], function() {
console.warn('Mycontroller');
this.sayMyNameService('Rafael');
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment