Discovering a problem
A new pet has arrived at the shop, so it's time to add him to the inventory. We'll add the following object to our animalData
array in animal.coffee
:
name: "Captain Chirp" type: "bird" age: 2 breed: "Parakeet" description: "Nice enough, though he strikes people as a bit... flighty."
But if we refresh the page, nothing shows up!
We've encountered an error in our code! Unfortunately, the error message is something like: TypeError: behavior is null at pet_view.js:34. This line number only applies to the compiled JavaScript, not to our CoffeeScript source.
One way to handle this is to find the corresponding line in pet_view.js
, read the compiled code, and work backwards to determine which line in CoffeeScript generated the erroring JavaScript. Thankfully, CoffeeScript produces fairly readable output, and we've been learning throughout this book to understand how our CoffeeScript compiles to JavaScript, so this is often a viable method. Still, this becomes more difficult as...