Skip to content

Instantly share code, notes, and snippets.

@kentcdodds
Created June 26, 2015 13:01
Show Gist options
  • Save kentcdodds/9b9913fec6afcb31bf6c to your computer and use it in GitHub Desktop.
Save kentcdodds/9b9913fec6afcb31bf6c to your computer and use it in GitHub Desktop.
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);
});
}
}
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