I have familiarity with different types of JavaScript function declarations such as expression functions and anonymous functions. However, I am unsure about the syntax used in these two specific functions: "manipulateData: function (input)" and "getDataById: function (id)". Can someone please enlighten me on what these functions are called?
Why does the return statement utilize a syntax that returns two functions? Why not just return one function at a time instead of both? If possible, could you provide some reference materials for clarification? Thank you.
app.service('MyService', function ($http, $q, $angularCacheFactory) {
var _dataCache = $angularCacheFactory('dataCache', {
maxAge: 3600000 // items expire after an hour
});
/**
* @class MyService
*/
return {
manipulateData: function (input) {
var output;
// perform data manipulation here
return output;
},
getDataById: function (id) {
var deferred = $q.defer();
if (_dataCache.get(id)) {
deferred.resolve(_dataCache.get(id));
} else {
// Retrieve data from server and populate cache
}
return deferred.promise;
}
};
});