Skip to main content
Active reading.
Source Link
Peter Mortensen
  • 31.3k
  • 22
  • 109
  • 132

someSome other people have touched on how to use the .bind() method, but specifically here is how you can use it with .then() if anyone is having trouble getting them to work together:

someFunction()
.then(function(response) {
    //'this' wasn't accessible here before but now it is            
}.bind(this))

EDIT: asAs mentioned in the comments, an alternative would be to use an arrow function that doesn't have its own 'this' value

someFunction()
.then((response)=>{
    //'this' was always accessible here         
})

some other people have touched on how to use the .bind() method, but specifically here is how you can use it with .then() if anyone is having trouble getting them to work together

someFunction()
.then(function(response) {
    //'this' wasn't accessible here before but now it is            
}.bind(this))

EDIT: as mentioned in the comments, an alternative would be to use an arrow function that doesn't have its own 'this' value

someFunction()
.then((response)=>{
    //'this' was always accessible here         
})

Some other people have touched on how to use the .bind() method, but specifically here is how you can use it with .then() if anyone is having trouble getting them to work together:

someFunction()
.then(function(response) {
    //'this' wasn't accessible here before but now it is
}.bind(this))

As mentioned in the comments, an alternative would be to use an arrow function that doesn't have its own 'this' value

someFunction()
.then((response)=>{
    //'this' was always accessible here
})
arrow functions don't have their own 'this'
Source Link
Josh McGee
  • 543
  • 9
  • 16

some other people have touched on how to use the .bind() method, but specifically here is how you can use it with .then() if anyone is having trouble getting them to work together

someFunction()
.then(function(response)=> {
    //'this' wasn't accessible here before but now it is            
}.bind(this))

EDIT: as mentioned in the comments, an alternative would be to use an arrow function that doesn't have its own 'this' value

someFunction()
.then((response)=>{
    //'this' was always accessible here         
})

some other people have touched on how to use the .bind() method, but specifically here is how you can use it with .then() if anyone is having trouble getting them to work together

someFunction()
.then((response)=>{
    //'this' wasn't accessible here before but now it is            
}.bind(this))

some other people have touched on how to use the .bind() method, but specifically here is how you can use it with .then() if anyone is having trouble getting them to work together

someFunction()
.then(function(response) {
    //'this' wasn't accessible here before but now it is            
}.bind(this))

EDIT: as mentioned in the comments, an alternative would be to use an arrow function that doesn't have its own 'this' value

someFunction()
.then((response)=>{
    //'this' was always accessible here         
})
Source Link
Josh McGee
  • 543
  • 9
  • 16

some other people have touched on how to use the .bind() method, but specifically here is how you can use it with .then() if anyone is having trouble getting them to work together

someFunction()
.then((response)=>{
    //'this' wasn't accessible here before but now it is            
}.bind(this))