I stopped at this issue 4h, if ignores my bool when Google maps event invoked. I need to give in parameters different data. Maybe on the world someone know why?
console.log throws after click in same time:
true before click
stack.html:56[object HTMLDivElement]in listener
stack.html:62[object HTMLDivElement]bunga bunga
broken bool:
this.b = true;
...
console.log(this.b + " beafore click");
this.mapListener = google.maps.event.addListener(map, 'click', function(e) {
console.log(this.b + "in listener");
if (this.b==true) {
console.log(this.b + "true works");
tools[type](e.latLng, last_marker_origin);
this.b = false;
} else {
console.log(this.b + "bunga bunga");
//tools[type](e.latLng);
}
});
this refers to “properties” in my object default set on false but when I change option it is flag to true.
I go to sleep for now. I’ll answer in the morning.
Your problem is that
thisis no longer a valid reference to yourproperties. The simplest way to deal with your specific problem is to change the code:The fundamental problem is that the code that actually makes the call to your callback function is in a completely different scope, so the meaning of
thishas changed when that code runs. Setting up a reference and putting that in the code will fix your problem.