Last active
November 14, 2019 21:09
-
-
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
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
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