JavaScript Inheritance and Object Programming

Coding Tutorial, Chapter 5d

Inherit Box Methods

© 21 July, 2013, Martin Rinehart


Results

Buttons added to your boxes.

Code

Add this comment and code line before your other Button prototype methods. (Reader Rajeev Bahuguna suggested using sum() in lieu of shallow_copy() to preserve the Button.prototype.constructor property.)



Our first Box objects were added to document.body. We should be able to add them inside other Box objects. We absolutely must be able to add Button objects inside Box objects. This requires improving the original appendChild() logic. (Note that this has nothing to do with inheritance, everything to do with appending to the DOM tree.)

As the comment shows, this comes at the end of Box.init().



Ready to test! Add some Buttons to your boxes. This one tests a custom background color.

Feedback: Martin Rinehart at gmail dot com.

# # #