Subclassing, Inheritance, RE subclass "constructor" and inherited members

V

vbgunz

// Referring to JavaScript the Definitive Guide: 9.5 through 9.5.2

// the base and sub classes are perfect. the following code is an
// example case, regarding WHY delete base members from a subclass
// AND what is wrong with the loops ONLY returning -> prototype :/

// Ex 01:
print(subInstance.hasOwnProperty("baseMember")); // false
for (var p in SubClass){
print(p);
} //
prototype


// Ex 02:
delete SubClass.prototype.baseMember; // Don't need to customize,
delete?
print(subInstance.hasOwnProperty("baseMember")); // false
for (var p in SubClass){
print(p);
} //
prototype

// Why delete the members in subclass if I inherit them from
baseclass? is it
// the same reason you might want to put constants & methods in the
prototype?
// Is it to avoid duplication and memory hogging? e.g., I don't
actually need
// to override the base members so should I really delete them from
subclass?

// Why iterating over the properties in the subclass yield ONLY ->
prototype?
// shouldn't I at least get all properties back defined in ALL classes
(Ex 01)
// AND after deleting those inherited from base on sub, shouldn't I at
least
// get those properties of sub (Ex 02)? Both Examples, have several
members!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top