The shortest I know would be avoiding using prototype in an outer scope and simply use closures:
function SomeSrvc($http, ...other deps...) {
var srvc = this;
srvc.doSomething = function() {
// just use $http without this / srvc
};
}
Short and nice. If you really like prototype-like syntax, just adjust the indentation (but in my opinion this would be uglier):
function SomeSrvc($http, ...other deps...) {
var srvc = this;
srvc.doSomething = function() {
// Do stuff with srvc.$http and other srvc.deps...
};
}
This gives you the same effect - the object created with a new operator will have this function and angular services are created this way.
Additionally, this way has a really good side-effect. It does not create the variables on the service object, so they can be considered private, when assigning all your variables to the service makes them public and could be accessed from another angular module. Currently by just injecting your service you are able to use all injected modules by just calling e.g.
SomeSrvc.$http
which is totally against the whole idea of dependency injection.
prototypeall that frequently ... But I've always liked it even if it is slightly more verbose.$injector.$injector? Does it change the verbose way of passing to prototype functions?function SomeSrvc($injector)thensrvc.$http = $injector.get('$http'), so you still have to assign it