Pass a function reference as callback to my service

I'm trying to refactor my code to avoid DRY and found that I'm doing the same stuff in two callback functions from my $resource. But I haven't managed to pass in a reference to a function instead of the function declaration itself.

I'm trying this:

emailService.getEmails(people, function(data) {
    data.foo();
});

But i want something like this:

emailService.getEmails(people, $scope.callback);

$scope.callback = function(data) {
    data.foo();
};

I don't seem to get it to work. Can I do this even?

It’s because $scope.callback isn’t defined (yet) when you run the emailService.getEmails function. You can change it to:

emailService.getEmails(people, callback);

function callback(data) {
    data.foo();
};