Closed twhtanghk closed 10 years ago
At last, I remove the static variable overlayOptions: {}; and replace the following assignment of member variable in constructor.
this.overlayOptions = options.overlayOptions || {};
That should do it for you.
I prefer:
_.extend(this.overlayOptions, options.overlayOptions);
as this allows you to set the instance variable as defaults, then override those defaults with options in the View constructor.
I try _.extend(this.overlayOptions, options.overlayOptions); before, but I found that the static variable would apply to all instances. That is, the last updated overlayOptions would apply to next created instance. Any other suggestion. Thanks.
You're right -- Backbone.extend
extends the child classes prototype
, which means that any changes to an instance property defined in extend
will be applied to all instances of the class. Best practice here would be to assign all instance properties within the initialize
method, instead
This is something that should be fixed for all the classes in the library. I can't get to it today, but it's going to the top of my list (unless you want to submit a pull request :) ).
Sorry for not updating this, but I believe this issue is resolved now.
See e8a52a5a57b6d5afc4837e270466cde7e73ddd93
MapView.overlayOptions is initialized as empty map. The condition "this.overlayOptions || (this.overlayOptions = options.overlayOptions)" for checking always return true if it is an empty map. It is suggested to revised as below. Any other suggestion.