Last active
September 29, 2017 19:12
-
-
Save batogov/68d2ecc4c6d016dac56ae9c5441c6a36 to your computer and use it in GitHub Desktop.
Custom bind [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
// В виде функции | |
function bind(func, context) { | |
return function() { | |
return func.apply(context, arguments); | |
}; | |
} | |
// В виде полифилла | |
if (!Function.prototype.bind) { | |
Function.prototype.bind = function(context) { | |
var funcToBind = this; | |
return function() { | |
return funcToBind.apply(context, arguments); | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment