Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

GEvent.addListener of the google map api

 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have two chunks of code, they both attempt to do the same thing - add an event listener to an object, a marker object. The marker object is a property of a tank_object class

One works and the other doesn't, i'd like to know why please.

This works fine; here i create a new tank_object and add a listener to the marker property of the tank_object:



however this doesn't; in the definition of tank_object class i add the listener to the property:



Why can't i attach my event listener to a property of tank_object during the 'definition' of that 'class'.

Please ignore any quarks with the code syntax, i'm missing an '_' in line 2 of first code chunk.
 
Sheriff
Posts: 67601
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does this reference in your function?
 
jite eghagha
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in a case where there is no default player_id; i had hoped 'this' would refer to player_id property of the object created by 'new'.


but suppose i was less ambiguous; like so.


i'd still have the same issue.

 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What bear is saying is that the scope of this in


is wrong. You need to make the scope correct like this



Do yourself a favor and read up on closures.

Eric
 
jite eghagha
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you Bear, thank you Eric


I'll read up 'closures' right away.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JavaScript's this is tricky (and fundamentally broken, IMO). You're just another victim.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic