0

イベントリスナーにいるときにオブジェクトのメンバーにアクセスするにはどうすればよいですか?ここに例があります、これは理解しやすくなると思います;)

MapProvider = function(mapID, autocompleteID) {
  // some other members
  MapProvider.prototype.map = null;
  MapProvider.prototype.autocomplete = null;

  // init function
  MapProvider.prototype.initAutocomplete = function() {  
   // some other stuff and now i create an autocompleteObj
   this.autocomplete = new google.maps.places.Autocomplete(this.inputField, myOptions);
   this.autocomplete.bindTo('bounds', this.map);

   // until now everything went fine
   // now i want to listen to the autocompleteObj
   // the handler is working fine aswell
   google.maps.event.addListener(this.autocomplete, 'place_changed', function() {
     // but now i want to acces the autocompleteObj again, but i cant :(
     // how can i access my members that i deklared in my first lines ?
     console.log(this.autocomplete.getPlace());
   });

 }

ありがとう :)

4

1 に答える 1

0

このようにしてみてください:

MapProvider = function(mapID, autocompleteID) {
    // some other members
    MapProvider.prototype.map = null;
    MapProvider.prototype.autocomplete = null;

    // init function
    MapProvider.prototype.initAutocomplete = function() {  

        this.autocomplete = new google.maps.places.Autocomplete(this.inputField, myOptions);
        this.autocomplete.bindTo('bounds', this.map);

        var _this = this;

        google.maps.event.addListener(this.autocomplete, 'place_changed', function() {

            console.log(_this.autocomplete.getPlace());
        });

    }
}
于 2012-11-18T13:34:47.197 に答える