2👍
✅
Probably the best way is to use the ES6 arrow function.
An arrow function expression has a shorter syntax compared to function expressions and lexically binds the this value (does not bind its own this, arguments, super, or new.target).
For your application it looks like this:
canvas.onclick = (evt) => {
console.log(this.originalData);
};
Or even:
canvas.onclick = e => console.log(this.originalData);
0👍
This is a little tricky in JavaScript. The this in your function points to the function. Since you are using typescript you probably have a class to wrap the variable and the function. You can try ClassName.originalData
Source:stackexchange.com