javascript - Extending google map api classes (or making wrappers) -


basically, wanted add few custom methods google.maps.map , rectangle classes. not it, decided make wrapper classes, ran 1 problem

function myclass() {    this.redraw_map = function() {draw something};   this.current_map = new google.maps.map();      google.maps.event.addlistener(this.current_map, 'bounds_changed', function() {     redraw_map();   }); } 

my redraw_map() method not seen in event handling function, unless put redraw method outside myclass. have in plans switch more advanced way writing js apps backbone, first need understand how overcome such problems.

thanks reading.

this happens because callback function you're passing addlistener not have function defined redraw_map() in current scope. workaround keep reference myclass scope outside of callback, allowing call inside callback.

this fix problem:

function myclass() {      this.redraw_map = function() {draw something};     this.current_map = new google.maps.map();        // reference current scope     var self = this;      google.maps.event.addlistener(this.current_map, 'bounds_changed', function() {         // call function defined in scope above         self.redraw_map();     }); } 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -