JSFiddle - React, Tailwind, and code Playground
by badsyntax
HTML
<h3>Overview</h3>
<p>Is it possible to list child object properties from a super object?</p>
JavaScript
var inherits=function(a,b){a.super_=b,a.prototype=Object.create(b.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}})};
/* Our super object */
var MySuper = function () {
this.superProp = 'hello';
};
MySuper.prototype.superMethod = function () {
return 'super';
};
MySuper.prototype.getChildPropertiesFromSuper = function() {
var props = [];
for(var prop in this) {
if (this.hasOwnProperty(prop) || this.constructor.prototype.hasOwnProperty(prop)) {
props.push(prop);
}
}
return props;
};
/* Our child object which inherits from super */
var MyChild = function () {
MySuper.apply(this, arguments);
this.childProp = 'hello';
};
inherits(MyChild, MySuper);
MyChild.prototype.childMethod = function () {
return 'child';
};
var child = new MyChild();
var props = child.getChildPropertiesFromSuper();
console.log(props); // ["superProp", "childProp", "childMethod"]