Great book. A joy to read and easy to follow so far. However I’d like chapter 4.2 ‘The Power of Prototypes’ and 4.3 on ‘Classes: Functions with Prototypes’ to give a few more examples.
One point I don’t quite understand is on p 58-59 (document coffeescript_b2_0.pdf):
Gift = (@name) -> Gift.count++ @day = Gift.count @announce()
Each time the Gift constructor runs, it does four things: Assigns the given name to @name (using the argument shorthand), increments the count property on the Gift prototype, copies that value to @day, and runs the @announce function inherited from the prototype. The important thing to notice here is that all of the functions on the new object run in the context of the object.
Why is count a property of the prototype? Isn’t it a property of the constructor?