I found the following code snippet here:
App.factory('myHttp',['$http',function($http) {
return function() {
get: function(url, success, fail) {
$http.get(url).success(function(response) {
return response.data;
}).error(fail);
}
};
}]);
I wonder what does this syntax mean:
function() {
get: function(...) { ... }
}
It looks like it’s a typo. It’s definitely a syntax error. It resembles the ES5 getter notation, but even so, you can only use that with a property name, like
get response() { ... }.Perhaps what the author intended was:
which is not the ES5 getter notation, but a simple object with one property called
get, referring to HTTP GET (as opposed to POST).