|
@@ -0,0 +1,87 @@
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+function myBind(func, myThis, myArray) {
|
|
|
+ return function (...arguments) {
|
|
|
+ let count = 0;
|
|
|
+ let tempArray = myArray.map((value) =>
|
|
|
+ (value === undefined ? arguments[count++] : value)
|
|
|
+ );
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return func.call(myThis, ...tempArray);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+var pow5 = myBind(Math.pow, Math, [undefined, 5])
|
|
|
+var cube = myBind(Math.pow, Math, [undefined, 3])
|
|
|
+
|
|
|
+pow5(2)
|
|
|
+cube(3)
|
|
|
+
|
|
|
+var chessMin = myBind(Math.min, Math, [undefined, 4, undefined, 5, undefined, 8, undefined, 9])
|
|
|
+chessMin(-1, -5, 3, 15)
|
|
|
+
|
|
|
+var zeroPrompt = myBind(prompt, window, [undefined, "0"])
|
|
|
+var someNumber = zeroPrompt("Введите число")
|
|
|
+
|
|
|
+myBind((...params) => params.join(''), null, [undefined, 'b', undefined, undefined, 'e', 'f'])('a', 'c', 'd') === 'abcdef'
|