Reputation: 81404
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?
Upvotes: 0
Views: 172
Reputation: 344605
Use the instanceof
operator:
if (this instanceof gtk.container) ...
Upvotes: 2