Created
August 25, 2017 07:53
-
-
Save jerrylau91/dbfde864fe40cede49728fd9f9e66cab to your computer and use it in GitHub Desktop.
JS Function.prototype.bind usage
This file contains hidden or 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
## What does Function.prototype.bind do ? | |
Function.prototype.bind = function (scope) { | |
if (typeof this !== "function") { | |
throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable"); | |
} | |
var fn = this; | |
return function () { | |
return fn.apply(scope); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
JavaScript 中的函数原型链中有一个 bind 方法,可以用来静态绑定函数的上下文。