I want to implement multiple inheritance using google closure . I have already researched and I found this book . At page 158, they say that google closure doesn't support multiple inheritance, but that there are other ways to do it, like using "goog.mixin". I tried it but I get "Uncaught AssertionError: Failure".
Basically, I want to do something like this:
class A {
function moveLeft() {
...
},
function moveRight() {
...
}
}
class B extends A {
function moveTop() {
...
}
}
class C extends B {
function moveBottom() {
...
}
}
BUT class C only gets the methods of class B the way I am doing.
How could I do this using google closure?
Thank you.
João
EDIT 1
I will try to make myself clearer. I can't display here the whole code for professional reasons. This is a bit how my classes look like.
// external file xgis.js
xgis = {};
// xgis.map
xgis.map = function(options) {
// map definitions ...
};
// Inherits from ol.Map
goog.inherits(xgis.map, ol.Map);
// xgis.layer
xgis.layer = function(options) {
// base layer definitions
};
// xgis.layer.osm
xgis.layer.osm = function(options) {
goog.base(this, {
source: new ol.source.OSM()
});
sigga.layer.call(this, options);
};
// Inherits from ol.layer.Tile
goog.inherits(xgis.layer.osm, ol.layer.Tile);
/**
* Copies all the members of a source object to a target object.
* i.e, inherits ALSO from xgis.layer (the base layer class)
*/
goog.mixin(xgis.layer.osm.prototype, xgis.layer.prototype);
The goal is to build an SDK, which I named here "xgis". We want to build our API on top of OpenLayers 3 (ol3). We want our own methods to use the ol3 methods. We need to have our own method for documenting.
For example, I want my own method to check the visibility of a layer. But this method has to use the one from ol3 "with the same name as mine":
// My method
xgis.layer.prototype.getVisible = function() {
// Used the method of the parent class from ol3
return this.superClass_.getVisible();
};
I tried to use the keyword "superClass_" to get the method of the parent class, but it didn't work.
Is there another way?
Can you write your example as valid JavaScript? As far as I can tell this isn't "multiple inheritance" but simply multiple levels of inheritance.
I think you mean:
function A() {}
A.prototype.moveLeft = function() {};
function B() {}
goog.inherits(B, A);
A.prototype.moveTop = function() {};
function C() {}
goog.inherits(C, B);
A.prototype.moveBottom = function() {};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.