eschwartz / backbone.googlemaps

A Backbone JS extension for interacting with the Google Maps API (v3.10)
MIT License
139 stars 55 forks source link

`this.options` undefined in constructor #17

Closed variousauthors closed 10 years ago

variousauthors commented 10 years ago

I'm having a bit of trouble. In the constructor for MapView (and most of your constructors) there are these references to this.options that are coming up undefined in my app. In particular, when the MarkerViewCollection is adding a child,

// in MarkerViewCollection->addChild
var markerView = new this.markerView({
    model: childModel,
    map: this.map
});

My experience is that the View constructor is only applying the model part of the options being passed in. The result is that on the indicated line (below) this.map and this.options are both undefined. Any clues as to why this might be happening? What was this.options intended to refer to? Why might map not be being applied to this?

// in MapView
constructor: function() {
    _.bindAll(this, 'render', 'close');
    Backbone.View.prototype.constructor.apply(this, arguments);
    // Ensure map and API loaded
    if(!google || !google.maps) throw new Error("Google maps API is not loaded.");
--> if(!this.options.map && !this.map) throw new Error("A map must be specified.");
    this.gOverlay = this.map = this.options.map || this.map;
    // Set this.overlay options
    this.overlayOptions || (this.overlayOptions = this.options.overlayOptions);
}, 

The map being passed in, by the way, is certainly defined.

Thanks!

variousauthors commented 10 years ago

Ah, this is a breaking change from Backbone 1.1.0. Here is the diff.