t-artistik / qtscriptgenerator

Automatically exported from code.google.com/p/qtscriptgenerator
0 stars 0 forks source link

A way to call base implementation of script class #54

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Consider: 

var w = new QWidget();
w.event = function(e) { ... };

How can one call the base implementation of QWidget::event()?

w.super_event(e);

is one possibility; e.g. generate such functions in the shell class.

Original issue reported on code.google.com by kentm...@gmail.com on 18 Nov 2009 at 12:18

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
There is a way to call the base class implementation of a method in standard 
ECMA
Script. Consider this class 'MyWidget', derived from 'QWidget':

// Constructor of MyWidget, calls constructor of QWidget
function MyWidget(parent) {
    QWidget.call(this, parent);
}

// MyWidget is derived from QWidget
MyWidget.prototype = new QWidget();

// MyWidget re-implements the event method and calls 
//   the event method from QWidget
MyWidget.prototype.event = function(e) {
    ...
    QWidget.prototype.event.call(this, e);
    ...
}

The problem with this attempt is that the call of the base class implementation
results in an endless recursion. As far as I understand, the event method of the
'QWidget' wrapper class is called, which then checks if there is an 'event' 
method
available in class 'MyWidget' and since this is the case, calls it.

A workaround is to 'hide' the 'event' method of MyWidget before calling the 
base class implementation:

MyWidget.prototype.event = function(e) {
    ...
    var eventMethod = MyWidget.prototype.event;
    MyWidget.prototype.event = undefined;
    QWidget.prototype.event.call(this, e);
    MyWidget.prototype.event = eventMethod;
    ...
}

IMHO, the wrappers should be fixed to also work without this workaround.

Original comment by ribbons...@gmail.com on 8 Apr 2010 at 9:08