Reputation: 9870
I was reading https://docs.angularjs.org/api/ng/function/angular.noop which has this example:
function foo(callback) {
var result = calculateResult();
(callback || angular.noop)(result);
}
I can't work out what this line is doing:
(callback || angular.noop)(result);
It looks like callback
and angular.noop
are functions that can return true
or false
, but what is the value used for, and what does (result)
do next to it?
Upvotes: 0
Views: 32
Reputation: 171679
The left side determines which function reference to use and the right side invokes that function passing in result
as parameter
In more verbose form it is the same as doing:
if (callback) {
callback(result)
} else {
angular.noop(result)
}
Upvotes: 1