Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't extend until constructor #7

Merged
merged 1 commit into from
May 23, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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