CoffeeScript Class Properties Within Nested Anonymous Functions
- by Aric
I'm just taking a look at CoffeeScript for the first time so bare with me if this is a dumb question. I'm familiar with the hidden pattern methodology however I'm still wrapping my head around object prototypes.
I'm trying to create a basic class for controlling a section on my site. The problem I'm running into is losing defined class variables within a different scope. For example, the code below works fine and creates the properties within the object perfectly. However when I jump into a jQuery callback I lose all knowledge of the class variables storing some of the jQuery objects for multiple uses.
Is there a way to grab them from within the callback function?
class Session
initBinds: ->
@loginForm.bind 'ajax:success', (data, status, xhr) ->
console.log("processed")
return
@loginForm.bind 'ajax:before', (xhr, settings) ->
console.log @loader // need access to Session.loader
return
return
init: ->
@loginForm = $("form#login-form")
@loader = $("img#login-loader")
this.initBinds()
return