I'm testing OpenLayers 6 beta. ol.inherits looks missing in OpenLayers 6.

ol.inherits(ol.source.NowMap, ol.source.OSM);

This causes error

Uncaught TypeError: ol.inherits is not a function

What should I use instead?

2 Answers 2


It's mentioned in the update notes https://github.com/openlayers/openlayers/blob/master/changelog/upgrade-notes.md

A simple fix which the ol-ext library uses is to replace it with the something based on the old function

var ol_ext_inherits = function(child,parent) {
  child.prototype = Object.create(parent.prototype);
  child.prototype.constructor = child;

or see the OL6 examples for a method which will need some recoding https://openlayers.org/en/master/examples/custom-controls.html https://openlayers.org/en/master/examples/custom-interactions.html

  • Thank you very much!
    – kochizufan
    Jun 3, 2019 at 1:04

Just a notice, as I do not have the reputation points requred for a proper comment. The suggested solutions is actually more in line with recomendations than the code given in the actual OpenLayers examples that are linked. Namely, the __proto__ method is deprecated and the proper method for inheritance is by using Object.create(). Link.




Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.