0

How to pass container variable to callback function geomapLoaded?

MyMap = Class.create({
    initialize: function(container) {
            this.container = container;
        google.load('visualization', '1', {'packages': ['geomap'], 'callback' : this.geomapLoaded});
    },

    geomapLoaded: function () {
        this.map      = new google.visualization.GeoMap(this.container);
    }
 }

I am getting this.container undefined in geomapLoaded method (I am using prototype framework).

1
  • Maybe closures can help you. Commented Mar 18, 2011 at 6:36

1 Answer 1

1

Like @David said in the comments, you should be able to use a closure to get round this. If you use an anonymous function instead of geomapLoaded then hopefully that will work:

MyMap = Class.create({
    initialize: function(container) {
        this.container = container;

        // Create a reference to this so we can use
        // it in our callback function
        var that = this;

        google.load('visualization', 
            '1', 
            {
                'packages': ['geomap'], 
                'callback' : function() {
                    that.map = new google.visualization.GeoMap(that.container);
                }
            }
        );
    }
 }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.