Skip to content

Instantly share code, notes, and snippets.

@benjaminRomano
Last active December 6, 2015 11:16
Show Gist options
  • Save benjaminRomano/2fc45eb4f3ba9303524c to your computer and use it in GitHub Desktop.
Save benjaminRomano/2fc45eb4f3ba9303524c to your computer and use it in GitHub Desktop.
class example
constructor() ->
@leftPanel = 5
#This is bad
@deletePaneCallback:(id) ->
console.log 'leftPane:' + @leftPanel #This will be undefined
#this is good
@deletePaneCallback2: (id) =>
cosole.log 'leftPane:' + @leftPanel # This will be 5
@consumeBottomDock: (@bottomDock) ->
@bottomDock.onDidDeletePane @deletePaneCallback
@bottomDock.onDidDeletePane @deletePaneCallback2
var example = function() {
this.leftPanel = 5;
this.deletePaneCallback(id) {
console.log('leftPanel:' + this.leftPanel); //This will be undefined
}
this.consumeBottomDock: (@bottomDock) ->
//This is the same as @deletePaneCallback
this.bottomDock.onDidDeletePane(this.deletePaneCallback); //This will be undefined
//This is the same as @deleteCallback2
this.bottomDock.onDidDeletePane(this.deletePaneCallback.bind(this)); //This will be 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment