title: Scope in coffeescript classes
body: <p>I would like to nest a number of functions inside a class property as shown below.<br>
  Unfortunately, they won't get access to the main scope of the class.</p>
  
  <p>Can I solve this without passing each nested function a reference to <code>this</code>?</p>
  
  <pre><code>class myClass
  
    constructor: -&gt; @errors = []
  
    doSomething: -&gt; @errors.push "I work as expected"
  
    functions:
      doStuff: -&gt;
        @errors.push "I cant access @errors" # =&gt; TypeError: Cannot call method 'push' of undefined
  
      ugly: (context) -&gt;
        context.errors.push "It works, but I am ugly" # Works fine but requires scope injection
  </code></pre>
  
  <p>Non-working alternative using suggested fat arrow:</p>
  
  <pre><code>class myClass
    constructor: -&gt;
      @errors = []
  
      @functions:
        doStuff: =&gt;
          @errors.push "I wont work either" # TypeError: Cannot call method 'toString' of undefined
  </code></pre>
  
  <p>Optional alternative, which doesn't write to the global <code>this.errors</code> property:</p>
  
  <pre><code>class myClass
  
    constructor: -&gt;
  
      @functions =
        errors: []
        doStuff: -&gt;
          @errors.push "I will write to functions.errors only"
  </code></pre>