Scoping issue when attempting to call CoffeeScript method inside Fancybox callback
<p>I have the following CoffeeScript module named Course. I have a small piece of code which I would like to re-use, I have created a method called <code>preSelectItemSize</code>.</p>

<p>I would like to call this method when <code>init</code> is called and also within the <code>afterShow</code> Fancybox callback. The following code <em>works</em>, but it don't believe it is correct to use the module name and I should be using the <code>@</code> reference to "this" instead.</p>

<p>What am I doing wrong? (Code snippet reduced for brevity)</p>

<pre><code>$ = window.jQuery = require("jquery")
Course =

  init: -&gt;

    $('.js-product-overlay').on 'click', (e) =&gt;
      @viewProductClickHandler(e, MediaDetection)

    @preSelectItemSize()

  viewProductClickHandler: (e, mediaDetection) =&gt;

    $('.js-product-overlay').fancybox({
      href: wishlist_overlay_href
      maxWidth: '775px'
      minHeight: '495px'
      autoCenter: '!isTouch'
      height: 'auto'
      scrolling: true
      fitToView: false
      autoSize: false
      padding: 0
      tpl:
        closeBtn: '&lt;a class="fancybox-item modal__close fancybox-close" href="javascript:;"&gt;Close&lt;/a&gt;'
      afterShow: -&gt;
        $('.js-fancybox-close').on 'click', (e) -&gt;
          e.preventDefault()
          $.fancybox.close()

        Course.preSelectItemSize()
    })

  preSelectItemSize: -&gt;
    itemId = $('.modal__product-info').attr('data-item-id')
    $('#size-' + itemId).click()

module.exports = Course
</code></pre>