Details
-
Suggestion
-
Resolution: Moved
-
P2: Important
-
None
-
None
Description
Background: ECMAScript can't mimic multiple inheritance "out of the box", since an object has only a single prototype link. When binding a class like QWidget, which inherits from QObject and QPaintDevice, this leads to the following issues:
1. Methods in the secondary base class are not available. The current solution is that the QWidget prototype has a property _QPaintDevice_, so you have to do something like
widget._QPaintDevice_.numColors.call(widget);
Another solution would be to copy all the properties in the QPaintDevice prototype that don't conflict with QWidget's prototype over to the QWidget prototype, but this is suboptimal.
2. The expression "widget instanceof QPaintDevice" evaluates to false, since this will use the standard Function [[HasInstance]] (which follows the single-prototype chain).
Maybe we can use a scheme similar to the one described here:
http://www.w3.org/TR/DOM-Bindings/#interface-prototype-object
In QtScript, this could be done by subclassing QScriptClass and keep a list of prototype objects that are looked up when a property is resolved.
There is no way currently to specify a custom [[HasInstance]]. This would have to be an extension to QScriptClass.