Vojta Jína: Test-Driven Design (in JavaScript)

Here’s a quick talk by Vojta Jína on:

On the last point, Vojta introduced three principles:

  1. Inversion of control (aka dependency injection)
  2. Avoid global, mutable state
  3. Law of demeter

On dependency injection: rather than (say) having a function which creates an object and then uses it, it’s better to provide the (already created) object as an argument to the function.

On global, mutable state: avoid it by (drumroll) passing it as an argument to the function!

On the law of demeter: objects should know as little about other objects in the system as is possible. So rather than (a) passing an object, (b) getting an attribute of that object and (c) using it (eg user.email), just pass the user’s email as an argument in the first place.