0

I'm using requireJS with googlemaps. I'm using plugin to load google maps: https://gist.github.com/taktran/5389668 (google maps api should be loaded with jQuery promise)

I have problem with "this" scope. Here is my code:

//funcs.js file  
  define('myFuncs', ['jquery', 'googleMaps'], function ($, googleMaps) {
      var myFuncs = {
        myVar="true";
        init: function () {
          googleMaps(this.map_init);
        },
        map_init:function () {
          //scripts after loading map
          console.log(this.myVar); //undefined
          console.log(this);//jQuery promise
          console.log(myFuncs.myVar); //true
      }
      return myFuncs;
    });

execute:

require(['funcs'], function (myFuncs) {
  myFuncs.init();
});

How to make this=myFuncs not jQuery promise??

3
  • 1
    this.myVar -> myFunds.myVar . Also, you have a syntax error. Alternatively function() { } -> function() { }.bind(myFuncs) and keep using this. Commented May 7, 2014 at 11:04
  • Whe I've added googleMaps(this.map_init(this)); this var i ok, but now new google.maps.LatLng(0,0); gives error Commented May 7, 2014 at 11:14
  • googleMaps(this.map_init.bind(this)); worked - thx Commented May 7, 2014 at 11:17

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.