Browse Source

Merge pull request #104 from kamil-kielczewski/patch-2

Update README.md
Martin Kleppe 4 năm trước cách đây
mục cha
commit
312b10b4d5
1 tập tin đã thay đổi với 23 bổ sung0 xóa
  1. 23 0
      README.md

+ 23 - 0
README.md

@@ -400,6 +400,29 @@ and finally:
 
 ```
 
+### Calling array method with more than one argument in "flow way"
+
+To call array methods in righthand side (flow) way" we use similar technique like for strings but with additional tricks (details [here](https://stackoverflow.com/q/63631908/860099)) presented in following example: `[3,4,5].slice(1,2).concat(6)` can be written as `[[3,4,5]].concat([[1,2]]).reduce([].slice.apply.bind([].slice)).concat(6)` (similar like for strings) but now we need to find right-hand side way to wrap array `[3,4,5]` and get `[[3,4,5]]` which can be done as follows `[3,4,5].map([].constructor).concat([[[]]])[0].slice(-1)` so we get
+
+```js
+[3,4,5]
+    // call: slice(1,2) 
+    .map([].constructor).concat([[[]]])[0].slice(-1)
+    .concat([[1,2]]).reduce([].slice.apply.bind([].slice))
+    // call next method (in flow)
+    .concat(6) 
+```
+and finally (after remove dots and commas)
+
+```js
+[3]["concat"](4)["concat"](5)
+    ["map"]([]["constructor"])["concat"]([[[]]])[0]["slice"](-1)
+    ["concat"]([[1]["concat"](2)])["reduce"]([]["slice"]["apply"]["bind"]([]["slice"]))
+    ["concat"](6) 
+```
+
+
+
 ### `number.toString(x)` – Getting any lowercase letter
 
 Number's `toString` method has an optional argument specifying the base to use (between 2 and 36). With base 36 we can retrieve any *lowercase* letter: