I am learning bind, call and apply functions. I am using bind to set callback for the api calls. Here are my functions:
function errorCallback(list, error) {
$log.error('Somehting went wrong while loading json.');
$log.log(list, error);
}
function successCallback(list, response) {
$log.info('JSON loaded successfully.');
//$log.log(list, response);
//this works
//$scope.list = list.concat(response.data);
//this doesn't
list = list.concat(response.data);
$log.log($scope.list, list);
}
This is how I am binding them:
var successCb = successCallback.bind(null, $scope.list),
errorCb = errorCallback.bind(null, $scope.list);
When I use them as callback:
$scope.loadJson = function() {
$http.get('data.json').then(successCb, errorCb);
};
They are getting invoked properly. But the concern is that when I update list , it does not update the actual parameter which is passed. I want to know that when we bind the parameters for bind, are they bound using value or reference? Here's the plunkr.