Created
November 9, 2014 01:27
-
-
Save snippe/c0fe47023dc01ba78239 to your computer and use it in GitHub Desktop.
.bind in JavaScript
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
this.statusId = 1; | |
var module = { | |
statusId : 4, | |
getStatus : function(){ | |
return this.statusId; | |
} | |
}; | |
console.log(module.getStatus()); //4 | |
var getModuleStatus = module.getStatus; | |
console.log(getModuleStatus()); //this refers to global //1 | |
var boundGetStatus = getModuleStatus.bind(module); | |
console.log(boundGetStatus()); //4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment