Extending Built-in Objects
Problem
You want to extend a class to add new functionality or replace old.
Solution
Use ::
to assign your new function to the prototype of the object or class.
Discussion
Objects in JavaScript (and thus, in CoffeeScript) have a prototype member that defines what member functions should be available on all objects based on that prototype. In CoffeeScript, you can access the prototype directly via the ::
operator.
Note: Although it’s quite common in languages like Ruby, extending native objects is often considered bad practice in JavaScript (see: Maintainable JavaScript: Don’t modify objects you don’t own; Extending built-in native objects. Evil or not?).