Daxbot / node-canopen

CANopen implementation for NodeJS
MIT License
32 stars 11 forks source link

[2.5.1] Pdo.start: wrong "this" binding in the listener functions #18

Closed bdcdekimo closed 3 years ago

bdcdekimo commented 3 years ago

When the listener function on pdo.js:104-106 gets executed, it has the "this" scope of the dataObject it was assigned to on line 113: entry.on('update', listener);. The problem is that you want to call Pdo.write(), so the "this" should be the Pdo and not the dataObject. Solved by replacling pdo.js:104-106 by an arrow function: const listener = () => this.write(cobId);

I haven't tested the other cases in Pdo.start(), but the other listener functions problably need similar fixes.