Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Inheritance, Composition and JavaScript's Types (Summary)

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

  1. A call takes the first match up the prototype chain. bricks.describe() starts at the object and finds the override in BuildingSet, on BuildingSet.prototype. The lookup stops there, so the line ends with the brick count.
  2. Use extends only for a real kind of thing. A building set is a toy, so BuildingSet 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.
  3. One method updates the toy and the member, after it checks.
  4. Set the error name once, in a base class, and catch the most specific class first. A LoanError is a LibraryError, and both are Error objects. So the catch block checks instanceof LoanError first, and a refused loan lands in its own branch.
  5. Convert typed text where it arrives. Typed values are text, so the text "3" plus 1 gives "31". Converted with readQuantity(), it gives 4.

Where to Go Next

RealJS has reference pages on each of these:

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.