Question
· Nov 23, 2016

Zen client methods and inheritance

I have a Zen page, and I would like to have an onload handler to run a bit of javascript when the page is ready. Unfortunately, the page inherits from a template, and the template already has an onload handler that does all kinds of useful things. Is there any way to override the onload handler in my page, while still being able to call the onload handler that is inherited from the template? In ObjectScript, there is ##super, but in javascript, there is no equivalent of that.

Discussion (2)0
Log in or sign up to continue

The Zen equivalent of ##super for JS is invokeSuper. Typically you'd just use:

this.invokeSuper('nameOfMethod',arguments);

All Zen components (including pages) have this. Here's an example from %ZEN.Component.dataCombo:

///  Set the value of a named property.<br>
ClientMethod setProperty(property, value, value2) [ Language = javascript ]
{
    switch(property) {
    case 'itemCount':
        break;
    case 'parameters':
        // set value of parameter: note that value will
        // be 1-based, so we have to convert it.
        // changing parameter always forces a query execution,
        // even in snapshot mode.
        if ('' != value) {
            value = value - 1;
            if (this.parameters[value]) {
                if (this.parameters[value].value != value2) {
                    this.parameters[value].value = value2;
                    this.clearCache();
                }
            }
        }
        break;
    default:
        // dispatch
        return this.invokeSuper('setProperty',arguments);
        break;
    }

    return true;
}