viewer.extend with class

Can i use viewer.extend with class not function, because Cesium throw exception VM5099:5 Uncaught TypeError: Cannot call a class as a function.

And i should use not Class.prototype.constructor


I'm trying to expand the viewer [viewer.extend] using classes ES6.
I have seen many examples and realized that mixins created as a function of. How correct create mixins?


viewer.extend expects the first parameter to be a function that adds additional functionality to the viewer. It calls this function with the viewer and the options that you passed in as the second paramater.

Take a look at the viewerCesiumInspectorMixin for an example:

If you wanted to use a class, you could create a helper function to do something like

MyClass.extendViewer = function(viewer, options) {
viewer.myClass = new MyClass(viewer, options)
viewer.extend(MyClass.extendViewer, options)




Thank you, but problem what context is lost. When pass my function in viewer.extend context `this` in MyClass is lost