Note that there are some explanatory texts on larger screens.

plurals
  1. POPrototype Class.create not subclassing properly
    text
    copied!<p>So, I'm trying to extend a google maps class, specifically google.maps.OverlayView (in v3). Doing it the vanilla js way totally works.</p> <pre><code>POIOverlay = function(marker, poi, type) { this._marker = marker; this._poi = poi; this._type = type; this._div = null; this.latlng_ = marker.getPosition(); this._map = marker.getMap(); this._offsetVertical = -195; this._offsetHorizontal = 0; this._height = 165; this._width = 266; } POIOverlay.prototype = new google.maps.OverlayView(); POIOverlay.prototype.create = function() { console.log(this) } POIOverlay.prototype.draw = function() { //stuff } </code></pre> <p>However, doing it the prototype way, fails to add any of the parent class methods:</p> <pre><code>POIOverlay = Class.create(new google.maps.OverlayView(), { initialize : function(marker, poi, type) { this._marker = marker; this._poi = poi; this._type = type; this._div = null; this.latlng_ = marker.getPosition(); this._map = marker.getMap(); this._offsetVertical = -195; this._offsetHorizontal = 0; this._height = 165; this._width = 266; }, create : function() { if(this._div) return; console.log(this); }, draw : function() { //stuff } }); </code></pre> <p>Here is the code to instantiate/use the class:</p> <pre><code> try { poio = new POIOverlay(marker,poi,type); } catch(e) { console.log(e); } google.maps.event.addListener(marker, 'click', poio.draw.bind(poio) ); </code></pre> <p>In the first example, the console logs an object with the parent and child methods/attributes. In the second example, the console logs an object with no parent attributes/methods.</p> <p>Obviously, this is not too big of a deal, but I was wondering in anyone else has run into this issue and if it is easily corrected. I am using prototype 1.7.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload