Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7429917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:03:29+00:00 2026-05-29T09:03:29+00:00

TL;DR Is PinView.prototype = _.extend(PinView.prototype, google.maps.OverlayView.prototype) the proper way to have a Backbone View

  • 0

TL;DR

Is PinView.prototype = _.extend(PinView.prototype, google.maps.OverlayView.prototype) the “proper” way to have a Backbone View inherit from another “class”?

Long read

We’re redoing our site using Backbone and are working on including some mapping functionality.

I’ve got a Backbone view that handles placing <div>s onto specific points within the browser window; this seems like a natural thing to extend in order have Google’s Map API place them on geographical coordinates.

According to the Google API, in order to generate a custom overlay you create a new object and set the prototype for that object to a new instance of google.maps.OverlayView. You then implement three functions on top of that object so that the object responds to:

onAdd

draw

onRemove

Where onAdd is responsible for generating the HTML and then applying it on top of the Map. This subsequently calls draw which positions the element correctly according to the LatLng pairs and bounds you’ve provided. onRemove gets called when you want to get rid of your layer.

So I’ve modified my View to include these three methods (which just call render and unrender and are bound to my collection). And then to make “the magic happen” I’m doing:

PinView.prototype = _.extend(PinView.prototype, google.maps.OverlayView.prototype)

Does this look right? I can post the code for the View and the Model on which it’s based, but honestly, they’re irrelevant to this example — the code works and I’m able to place custom divs generated through Backbone model, view and controller components on the map without a issue, what I’m asking I guess (and maybe this question is more apropos for programmers.se, so let me know and I’ll move it).

This seems to be the easiest way to make my PinView both a Backbone View and a Google Maps OverlayView, but I’m not 100% comfortable with prototypal inheritance to know if I’m doing something “wrong” or breaking something somewhere down the road.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T09:03:30+00:00Added an answer on May 29, 2026 at 9:03 am

    Nice idea! I’m usually a bit sceptical about weather or not you’re ‘correct’ when things work so if you haven’t run into a showstopper and the overlays shows up and does what the’re supposed to do I’d say you are.

    One thing to check out closer, though:

    This isn’t (and can’t) be “real” multiple inheritance – that concept isn’t really relevant in a prototype based language: one implementation of a method will inevitable “win” and overwrite the other implementation, at least when using _.extend()

    This means that if there are members or methods with the same names in Backbone.View and google.maps.OverlayView the one last in your _.extend() call will be the one that takes over. But when I inspect them using Chrome’s Developer Tools I didn’t see any obvious collision of this kind.

    So my recommendation: continue using this, just test a lot. I’d love to see an example of this technique some time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im have a subclass of UIView, called PinView, which contains an image. Basically PinView
I have some map view controller and I have a custom annotation. Custom annotation
I have a map view with pins annotations into it. I need to pass
The code I have is: MKPinAnnotationView *pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@Pin]; if(pinView == nil)
It works the same way in Maps.app: when you tap and hold for a
I have a view which is presented as a modal view controller which takes
I have set up an MKMapView with MKAnnotationView s for a bunch of locations.
I have a number of annotations on my map, in addition to the users
I would like to emulate the 'Drop Pin' feature in the Maps application. I
I have little problem with my iphone application. I have such classes and interfaces:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.