Created
February 20, 2019 14:39
-
-
Save yairEO/19fbf1864b96b6ca519832728ba48b28 to your computer and use it in GitHub Desktop.
deepBind for object methods at any depth with any context
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
function deepBind(O){ | |
for(var key in O) | |
// if value is an object, go deeper | |
if( O[key] instanceof Object && typeof O[key] == 'object' ) | |
deepBind.call(this, O[key]) | |
// look for a value which is a function and bind it | |
else if( typeof O[key] == 'function' ) | |
O[key] = O[key].bind(this); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: