-
Book Overview & Buying
-
Table Of Contents
CoffeeScript Application Development
By :
Inheritance is a powerful concept that many modern programming languages use extensively. JavaScript has never embraced it wholeheartedly, in large part because implementing it has always been slightly awkward and error-prone due to some omissions in the JavaScript language. Thankfully, CoffeeScript patches up those holes and makes inheritance a first-class experience again.
Inheritance is used to define is-a relationships, such as "an Apple is a type of Fruit". Child classes (like Apple) inherit behavior from parent classes (like Fruit), while often adding more behavior or selectively modifying existing behavior. Inheritance can be chained through several generations, and a child inherits behavior from all of its ancestors, with priority given to the nearest. This is a powerful mechanism for code reuse, and is a good way to model many logical relationships.
Be cautious not to overuse inheritance. There are other ways to reuse code, so don't force inheritance onto a relationship...
Change the font size
Change margin width
Change background colour