2π
β
The closure of this
in function(){ //code } is the function itself. If you want to access the this
of the object which you defined the function you will need to use arrow function as follow.
var obj = {
getToDos() {
// this here refer to obj
axios.get('/todo')
.then( res => {
this.todos = res.data
})
}
}
More information about closure in js:
https://www.w3schools.com/js/js_function_closures.asp
https://medium.com/@vmarchesin/javascript-arrow-functions-and-closures-4e53aa30b774
π€HW Siew
Source:stackexchange.com