topical media & game development
professional-javascript-04-zinherit.js / js
Object.prototype.inheritFrom = function (fnClass) {
function inheritClasses(fnClass, arrClasses) {
arrClasses.push(fnClass);
if (typeof fnClass.__superclasses__ == "object") {
for (var i=0; i < fnClass.__superclasses__.length; i++){
inheritClasses(fnClass.__superclasses__[i], arrClasses);
}
}
}
if (typeof this.constructor.__superclasses__ == "undefined") {
this.constructor.__superclasses__ = new Array();
}
inheritClasses(fnClass, this.constructor.__superclasses__);
for (prop in fnClass.prototype) {
if (typeof fnClass.prototype[prop] == "function") {
this[prop] = fnClass.prototype[prop];
}
}
};
Object.prototype.instanceOf = function (func) {
if (this.constructor == func) {
return true;
} else if (typeof this.constructor.__superclasses__ == "object") {
for (var i=0; i < this.constructor.__superclasses__.length; i++) {
if (this.constructor.__superclasses__[i] == func) {
return true;
}
}
return false;
} else {
return false;
}
};
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.