Skip to content

Commit

Permalink
Merge pull request #7 from ethanclevenger91/extend
Browse files Browse the repository at this point in the history
Don't extend until constructor
  • Loading branch information
jesstelford committed May 23, 2016
2 parents aa81cd0 + a8bd275 commit 7f0a7e1
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@
/*global document,google */

/**
* @param {Function} childCtor Child class.
* @param {Function} parentCtor Parent class.
* @param {Function} obj1 Child class.
* @param {Function} obj2 Parent class.
*/
function inherits(childCtor, parentCtor) {
/** @constructor */
function tempCtor() {};
tempCtor.prototype = parentCtor.prototype;
childCtor.superClass_ = parentCtor.prototype;
childCtor.prototype = new tempCtor();
/** @override */
childCtor.prototype.constructor = childCtor;
MarkerLabel_.prototype.extend = function(obj1, obj2) {
return (function(object) {
for (var property in object.prototype) {
this.prototype[property] = object.prototype[property];
}
return this;
}).apply(obj1, [obj2]);
};
}

/**
Expand All @@ -59,6 +59,7 @@ function inherits(childCtor, parentCtor) {
* @private
*/
function MarkerLabel_(marker, crossURL, handCursorURL) {
this.extend(MarkerLabel_, google.maps.OverlayView);
this.marker_ = marker;
this.handCursorURL_ = marker.handCursorURL;

Expand All @@ -79,7 +80,6 @@ function MarkerLabel_(marker, crossURL, handCursorURL) {
// Get the DIV for the "X" to be displayed when the marker is raised.
this.crossDiv_ = MarkerLabel_.getSharedCross(crossURL);
}
inherits(MarkerLabel_, google.maps.OverlayView);

/**
* Returns the DIV for the cross used when dragging a marker when the
Expand Down Expand Up @@ -536,6 +536,7 @@ MarkerLabel_.prototype.setVisible = function () {
* @param {MarkerWithLabelOptions} [opt_options] The optional parameters.
*/
function MarkerWithLabel(opt_options) {
this.extend(MarkerWithLabel, google.maps.Marker);
opt_options = opt_options || {};
opt_options.labelContent = opt_options.labelContent || "";
opt_options.labelAnchor = opt_options.labelAnchor || new google.maps.Point(0, 0);
Expand Down Expand Up @@ -569,7 +570,15 @@ function MarkerWithLabel(opt_options) {
// that the marker label listens for in order to react to state changes.
google.maps.Marker.apply(this, arguments);
}
inherits(MarkerWithLabel, google.maps.Marker);

MarkerWithLabel.prototype.extend = function(obj1, obj2) {
return (function(object) {
for (var property in object.prototype) {
this.prototype[property] = object.prototype[property];
}
return this;
}).apply(obj1, [obj2]);
};

/**
* Overrides the standard Marker setMap function.
Expand Down

0 comments on commit 7f0a7e1

Please sign in to comment.