testing if constructor in constructor chain

Posted by Delan Azabani on Stack Overflow See other posts from Stack Overflow or by Delan Azabani
Published on 2010-12-23T11:38:48Z Indexed on 2010/12/23 11:53 UTC
Read the original article Hit count: 348

Filed under:

I'm attempting to implement a GTK+ inspired widget toolkit for the web in JavaScript. One of the constructor chains goes

gtk.widget => gtk.container => gtk.bin => gtk.window

Every gtk.widget has a showAll method, which, if and only if the widget is a gtk.container or derivative (such as gtk.bin or gtk.window), will recursively show the children of that widget. Obviously, if it isn't a gtk.container or derivative, we shouldn't do anything because the widget in question can't contain anything.

For reference, here is my inheritance function; it's probably not the best, but it's a start:

function inherit(target, parent) {
    target.prototype = new parent;
    target.prototype.constructor = target;
}

I know that I can check for the direct constructor like this:

if (this.constructor === gtk.container) ...

However, this only tests for direct construction and not, say, if the object is a gtk.bin or gtk.window. How can I test whether gtk.container is somewhere up in the constructor chain?

© Stack Overflow or respective owner

Related posts about JavaScript