Skip to content

Instantly share code, notes, and snippets.

@batogov
Last active September 29, 2017 19:12
Show Gist options
  • Save batogov/68d2ecc4c6d016dac56ae9c5441c6a36 to your computer and use it in GitHub Desktop.
Save batogov/68d2ecc4c6d016dac56ae9c5441c6a36 to your computer and use it in GitHub Desktop.
Custom bind [JavaScript]
// В виде функции
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