I can't find the right term relating to this thing, so I decided to write a question.
I have this function:
var methods = {
login: function(callback){
$someCustomService
.login() // This returns $http
.success(function(data){
// callback(true, data); --- doing this without using 'return' also works
return callback(true, data);
})
.error(function(data){
return callback(false, data);
})
}
};
Call the function:
$anotherCustomService.login(function(success, data){
if(success){
alert('Success');
}else{
alert('Fail');
}
console.log(data);
});
The line return callback(true, data);
works just fine, but if I changed it to callback(true, data);
without using return
it also works. Now I'm confused whether what to use.
EDIT
BTW, the main reason I ask this, is because of this:
angular.noop
function foo(callback) {
var result = calculateResult();
(callback || angular.noop)(result);
}
It didn't use any return
which I learned first in coding javascript functions.