-
-
Save mxriverlynn/11959c1f0c9a0f67c010 to your computer and use it in GitHub Desktop.
managing javascript this with es6 arrow functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
someFunction( (arg1, arg2, argN) => { | |
// function body | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
someFunction( function(arg1, arg2, argN) { | |
// function body | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var orgChart = { | |
addNewEmployee: function(){ | |
var employeeDetail = this.getEmployeeDetail(); | |
// => arrow function used here | |
employeeDetail.on("complete", (employee) => { | |
// "this" comes from the surrounding code | |
this.selectManager(employee); | |
}); | |
}, | |
selectManager: function(employee){ | |
// do stuff to select the manager | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
orgChart.addNewEmployee(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var add = orgChart.addnewEmployee; | |
add(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment