getMessageCount
is a function returning a promise object. then
method of this promise returns another promise
again. It makes possible to chain multiple then
parts. Each then(function() { ... })
has an ability to modify a data to be passed to the next then
invocation. So this construction:
return datacontext.getMessageCount().then(function(data) {
return vm.messageCount = data;
});
means to modify a data passed to resolve callbacks. Without this return
success functions would be resolved with undefined value, while we need it to be resolved with data
.