Skip to content

Commit 6403c07

Browse files
committed
Implementing bind
1 parent 8508aba commit 6403c07

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

implementations/bind.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
*
3+
bind() creates a new function. When this function is invoked, it is called with the arguments and in the context passed.
4+
5+
bind() has two parameters:
6+
- Context: the value that is passed as this value in the new function.
7+
- Arguments: arguments passed to the new function.
8+
*/
9+
10+
Function.prototype.myBind = function myBind(newContext) {
11+
const fnArguments = Array.prototype.slice.call(arguments, 1);
12+
13+
oldContext = this;
14+
return () => oldContext.apply(newContext, fnArguments);
15+
};

0 commit comments

Comments
 (0)