Skip to content

Instantly share code, notes, and snippets.

@mxriverlynn
Last active September 1, 2015 01:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mxriverlynn/11959c1f0c9a0f67c010 to your computer and use it in GitHub Desktop.
Save mxriverlynn/11959c1f0c9a0f67c010 to your computer and use it in GitHub Desktop.
managing javascript this with es6 arrow functions
someFunction( (arg1, arg2, argN) => {
// function body
});
someFunction( function(arg1, arg2, argN) {
// function body
});
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
}
};
orgChart.addNewEmployee();
var add = orgChart.addnewEmployee;
add();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment