Guest User

Untitled

a guest
Mar 23rd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. const defaultArgs = {
  2. like: false
  3. }
  4.  
  5. const dependencies = {
  6. goToExternalService: require('pathToExternalService')
  7. }
  8.  
  9. //a binary function...
  10. /*The first argument is a JSON as the list of arguments*/
  11. /*The second argument is the injection*/
  12. function foo(args, injection) {
  13. const { language, like } = Object.assign({}, defaultArgs, args) //do not use args directly
  14. const { goToExternalService } = Object.assign({}, dependencies, injection) //neither injection
  15.  
  16. return goToExternalService(language, like)
  17. }
  18.  
  19. //...consumed as unitary!
  20. foo({ language: 'js', like: true })
  21. foo({ language: 'c#', like: true })
  22. foo({ language: 'java' })
Add Comment
Please, Sign In to add comment