I'm not sure how you're normally supposed to handle this within Atom Packages, but this is the situation:
I created a beautiful button
playButton = document.createElement('button');
playButton.onclick = @funkyFreshCallback;
funkyFreshCallback: (event, element) ->
You can bind the parent context onto the function before setting it up as the event handler.
playButton.onclick = @funkyFreshCallback.bind(@);
Another way to avoid the context issue is to setup a function that calls
funkyFreshCallback. The event handler should only handle the event and then pass along the minimum set of required data to the callback, like so:
playButton.onclick = (event, element) => timePressed = Date.now(); @funkyFreshCallback(timePressed);
With the code above, funkyFreshCallback will be called with the context that you expect, and won't receive a really complex event object as an argument. This helps to make writing unit tests for
funkyFreshCallback easier, and it should simplify your callbacks, because they won't have to deal with events.