You’ve finished Inheritance, Composition and JavaScript’s Types.
What You Can Do Now
- Design a small family of classes.
- Choose composition where inheritance doesn’t fit.
- Define custom errors.
- Convert values explicitly where they enter a program.
- Build a program from a brief, then plan one of your own.
Things to Remember
- A call takes the first match up the prototype chain.
bricks.describe()starts at the object and finds the override inBuildingSet, onBuildingSet.prototype. The lookup stops there, so the line ends with the brick count. - Use
extendsonly for a real kind of thing. A building set is a toy, soBuildingSet extends Toy. Everything else is a part: a lending desk isn’t a toy, so it holds toys, members, and a loan policy. Swap in the winter policy, and the slip says three weeks. The desk’s code doesn’t change. - One method updates the toy and the member, after it checks.
- Set the error name once, in a base class, and catch the most specific class first. A
LoanErroris aLibraryError, and both areErrorobjects. So the catch block checksinstanceof LoanErrorfirst, and a refused loan lands in its own branch. - Convert typed text where it arrives. Typed values are text, so the text
"3"plus1gives"31". Converted withreadQuantity(), it gives4.
Where to Go Next
RealJS has reference pages on each of these: