Google Maps Trouble: Closures & Passing By Reference

前端 未结 2 1289
无人及你
无人及你 2021-01-13 09:37

I\'m having some Google Maps/Javascript problems. I think I know what the trouble is but just don\'t know a way round it.

An example of my problem is here. Whateve

2条回答
  •  耶瑟儿~
    2021-01-13 10:03

    The above answer is not very intuitive though - as Greg said.

    When you add an event to an object, that object is passed down so you can access it by "this" within the closure. If you replaced "marker.value" with "this.value" your problem would have been resolved. If you need to pass down more stuff, you tie it to the object and pass it down:

    marker.a = 1
    marker.b = 2
    marker.c = 3
    

    Within the closure this.a will be 1 and so on..

提交回复
热议问题