0

I'm running into a strange "bug?" when I try to override a insert.onChange method, and call the original from within the override. Here's my callstack, where I'm getting an error because event is undefined:

enter image description here

Now here is one frame deeper in the stack, and as you can see, the _onChange method is pointing to the function we've just defined, even though I've referenced the original function (insert.onChange) outside the scope of the new function:

enter image description here

To me what's really strange is that the second time through the loop, at the top of the callstack, the _onChange now references the correct original (anonymous) function.

enter image description here

I've tried wrapping it in more closures and have read over the other answers on SO about overriding and calling the original method in JS. Any help understanding what I'm doing wrong would be great.

Thanks! Thomas

tnrich
  • 8,006
  • 8
  • 38
  • 59

1 Answers1

0

as you can see, the _onChange method is pointing to the function we've just defined

No. I see that references the original function that was insert.onChange before you've overwritten it. Notice that function (debugging) names don't change through execution. The name insert.onChange doesn't mean that it's the current onChange property of the insert object.

the second time through the loop, the _onChange now references the correct original (anonymous) function.

No. It now references your own anonymous function that you used for overwriting insert.onChange the first time - which was the value of the onChange property when you've overwritten it the second time.

You really should try to name your function to get more accurate debugging information.

Community
  • 1
  • 1
Bergi
  • 630,263
  • 148
  • 957
  • 1,375