From 6403c07847609466c1087115af06ec5da95991fa Mon Sep 17 00:00:00 2001 From: Arthur Teixeira Date: Tue, 8 Oct 2019 20:33:24 -0300 Subject: [PATCH 1/3] Implementing bind --- implementations/bind.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 implementations/bind.js diff --git a/implementations/bind.js b/implementations/bind.js new file mode 100644 index 0000000..387b140 --- /dev/null +++ b/implementations/bind.js @@ -0,0 +1,15 @@ +/** + * + bind() creates a new function. When this function is invoked, it is called with the arguments and in the context passed. + + bind() has two parameters: + - Context: the value that is passed as this value in the new function. + - Arguments: arguments passed to the new function. +*/ + +Function.prototype.myBind = function myBind(newContext) { + const fnArguments = Array.prototype.slice.call(arguments, 1); + + oldContext = this; + return () => oldContext.apply(newContext, fnArguments); +}; From 74158a9ee4b1bab1bbd0b034a8dae4579b7fbf90 Mon Sep 17 00:00:00 2001 From: Arthur Teixeira Date: Tue, 8 Oct 2019 20:34:42 -0300 Subject: [PATCH 2/3] Revert "Implementing bind" This reverts commit 6403c07847609466c1087115af06ec5da95991fa. --- implementations/bind.js | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 implementations/bind.js diff --git a/implementations/bind.js b/implementations/bind.js deleted file mode 100644 index 387b140..0000000 --- a/implementations/bind.js +++ /dev/null @@ -1,15 +0,0 @@ -/** - * - bind() creates a new function. When this function is invoked, it is called with the arguments and in the context passed. - - bind() has two parameters: - - Context: the value that is passed as this value in the new function. - - Arguments: arguments passed to the new function. -*/ - -Function.prototype.myBind = function myBind(newContext) { - const fnArguments = Array.prototype.slice.call(arguments, 1); - - oldContext = this; - return () => oldContext.apply(newContext, fnArguments); -}; From bc4072cefcf3ce577ec9b82a5e19c183c90f6c03 Mon Sep 17 00:00:00 2001 From: Arthur Teixeira Date: Tue, 8 Oct 2019 20:35:26 -0300 Subject: [PATCH 3/3] Implementing bind --- implementations/bind.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 implementations/bind.js diff --git a/implementations/bind.js b/implementations/bind.js new file mode 100644 index 0000000..387b140 --- /dev/null +++ b/implementations/bind.js @@ -0,0 +1,15 @@ +/** + * + bind() creates a new function. When this function is invoked, it is called with the arguments and in the context passed. + + bind() has two parameters: + - Context: the value that is passed as this value in the new function. + - Arguments: arguments passed to the new function. +*/ + +Function.prototype.myBind = function myBind(newContext) { + const fnArguments = Array.prototype.slice.call(arguments, 1); + + oldContext = this; + return () => oldContext.apply(newContext, fnArguments); +};