I am converting some code to ES6, and in one part I am trying to understand fat arrow binding. I had code like this:
function callApi(api, payload, header) {
$http.post(api, payload, header)
.success(function(data) {...})
.error(function (data, status) { handleError(data, status) })
}
function handleError(data, status) {...}
I have changed that to this, which works:
callApi(api, payload, header) {
this.$http.post(api, payload, header)
.success((data) => {...})
.error((data, status) => this.handleError(data, status))
}
handleError(data, status) {...}
What doesn't work is when I tried to call handleError like this:
.error((data, status) => this.handleError)
I thought that might be delegating the error handling to the handleError function, but it doesn't. Can someone help me understand what I'm misunderstanding about arrow binding that it can't be used like ()=>myFunction, and is there a way to do delegation like this that incorporates binding this
?