0

I am trying to test passing parameters from a function to another function on mouse click but I am getting a

"Uncaught TypeError: this.updateList is not a function"

I want to pass the updateList() function the index of the object that is clicked. I am unsure why this is happening. Any help would be appreciated- here is my code snippet below:

  teamAgg.on('click', function(d, i) {

        this.updateList(i);

    });
};

updateList(i) {
    let i = i; 
    console.log('test: ' + i);
}
Sockness_Rogers
  • 1,693
  • 3
  • 12
  • 23
  • 1
    It's hard to be sure given the fragmentary nature of the quoted code, but if `updateList` really is a method on an object that you'd be able to use as `this` in the same scope where you call `.on`, the linked question's answers tell you why `this` in the `.on` callback isn't the same, and what to do about it. – T.J. Crowder Oct 11 '17 at 14:01
  • 1. "this.updateList(i);" "this" is in the scope og the click function 2. "let i = i;" "i" is already defined, you will get an error like "'i' has already been declared" 3. this line "updateList(i) {..." just begins with a constant-like name did you mean "var updateList(i){"? – Ben jamin Oct 11 '17 at 14:10

0 Answers0