-1

I have this function call in jQuery:

image.save(comment);

and I've defined the save function like this:

Image.prototype.save = association => {
  debugger;
  this
}

How do I get this to equal the recipient of the function call which is image? Right now at the debugger, it equals the window object.

Gabriele Petrioli
  • 183,160
  • 33
  • 252
  • 304
Jwan622
  • 9,962
  • 16
  • 68
  • 147

1 Answers1

1

Do not use arrow functions

Arrow functions have a lexical this; its value is determined by the surrounding scope.

Image.prototype.save = function(association){
  debugger;
  this
}
Gabriele Petrioli
  • 183,160
  • 33
  • 252
  • 304