CHAPTER 17 Ensuring Correct Argument Types


  • Augmenting Chapter 16’s ContractRegistry to handle argument validation
  • Packaging the new facility in an aspect
  • Creating libraries of contracts, importing them into your application, and attaching them to your functions in aspects
  • Comparing the ContractRegistry with TypeScript, a popular compile-time type-checker


You can find the code downloads for this chapter at on the Download Code tab. The files are in the Chapter 17 download and individually named according to the filenames noted throughout this chapter.

In strongly typed languages, you always know what you’re going to get. If a function is declared with an integer parameter, you can be sure that an integer is exactly what will come across the call boundary. With this sort of rock-solid assurance, it is no wonder that mainframe banking systems, transportation systems, and especially defense systems are implemented in strongly typed languages such as Java, C#, COBOL, and Ada.

If Java is a banker and Ada a general, JavaScript is a scrappy entrepreneur, creatively making deals and attracting new customers. It is entirely fitting that JavaScript has become the language of the customer-facing portion of e-commerce, where agility, efficiency, and expressiveness are highly prized.

Sometimes an entrepreneur hits the big-time and decides to become a venture capitalist. ...

Get Reliable JavaScript: How to Code Safely in the World's Most Dangerous Language now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.