Skip to content
Advertisement

why can’t access the function inside the listener

I am using a class component. When I run this script, it plots the graphic, but in the next line when it calls the function computePM_from_ClickedPoint, I get the error below. The error refers to “this”, but without it, I cannot call the function. Suggestions?

Error: Cannot read properties of undefined (reading 'computePM_from_ClickedPoint')

JavaScript

tried unsuccessfully changing the call to:

JavaScript

Advertisement

Answer

Instead of bindingthis.computePM_from_ClickedPoint(graphic.geometry).bind(this) try to bind to this.enableMapClick on onClick event (this way you can call it with this/Class same specific object), something like.

JavaScript

For more details:- javascript-bind-method

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement