Created
June 26, 2015 13:01
-
-
Save kentcdodds/9b9913fec6afcb31bf6c to your computer and use it in GitHub Desktop.
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
class Foo { | |
constructor($http, $log, WhateverElse) { | |
// This is the boilerplate I'm talking about | |
this.$http = $http; | |
this.$log = $log; | |
this.whateverElse = WhateverElse; | |
// anytime I add something, I have to add it here | |
// anytime I remove something, I have to remove it from here | |
// I just don't really see what classes are getting me from | |
// a reusability/maintainability/readability/whatever standpoint. | |
} | |
doSomething() { | |
return this.$http.get('some/url').then(response => { // <-- thank you arrow function! lexical scoping | |
this.$log.info('Got something', response); | |
this.whateverElse(response); | |
}); | |
} | |
} |
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
function Foo($http, $log, WhateverElse) { | |
return {doSomething}; | |
function doSomething() { | |
return $http.get('some/url').then(response => { | |
$log.info('Got something', response); | |
WhateverElse(response); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment