Trick to access original context
Trick to access original context when using $.proxy
by bjoerne
CoffeeScript
# If you don't know Coffeescript convert the code with http://js2coffee.org/
class @Example
init: ->
# Trick 1
that = @
window.setTimeout ->
Example.prototype.logThisAndOriginalContext.call that, @
, 0
# Trick 2
window.setTimeout ((instance) ->
->
Example.prototype.logThisAndOriginalContext.call instance, @
)(@), 0
logThisAndOriginalContext: (originalContext) ->
console.log @
console.log originalContext
new Example().init()