title: Using util.inherits() "breaks" prototyping when using CoffeeScript
body: <p>I encountered a problem after switching from server-side JavaScript to CoffeeScript in a Node.js application. Let's consider the following code: </p>
  
  <pre><code># require our tools
  util = require "util"
  events = require "events"
  
  # define an object class and a method using CoffeeScript syntax
  class TestObject
    method: () -&gt; #1
      console.log "Test"
  
  # set up inheritance using Node.js util module
  util.inherits TestObject, events.EventEmitter #2
  
  # make an instance of object
  instance = new TestObject()
  
  # and boom! it crashes ;(
  instance.method()
  </code></pre>
  
  <p>The above code will crash because of the error: <code>TypeError: Object #&lt;TestObject&gt; has no method 'method'</code></p>
  
  <p>The error is caused by setting up the inheritance at <code>#2</code>. The above code compiles to following JavaScript (deleted some newlines for the sake of readability):</p>
  
  <pre><code>(function() {
    var TestObject, events, instance, util;
  
    util = require("util");
    events = require("events");
  
    TestObject = (function() {
      function TestObject() {}
  
      TestObject.prototype.method = function() {
        return console.log("Test");
      };
  
      return TestObject;
    })();
  
    util.inherits(TestObject, events.EventEmitter);
  
    instance = new TestObject();
    instance.method();
  
  }).call(this);
  </code></pre>
  
  <p>You can see that the <code>util.inherits()</code> method is called after adding the method to prototype. So, the method would be lost after switching prototypes.</p>
  
  <p>Is there an elegant way to set up the inheritance without breaking the awesome CoffeeScript class notation?</p>