-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
  • 191,379
  • 34
  • 261
  • 317
Jwan622
  • 11,015
  • 21
  • 88
  • 181

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
  • 191,379
  • 34
  • 261
  • 317