You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here's a [generic loop function](https://gist.github.com/bendc/6cb2db4a44ec30208e86) making recursion easier to use.
610
+
600
611
### Arguments
601
612
602
613
Forget about the `arguments` object. The rest parameter is always a better option because:
@@ -680,21 +691,15 @@ Avoid nesting functions when you don't have to.
680
691
Avoid multiple nested function calls. Use composition instead.
681
692
682
693
```javascript
683
-
// bad
684
694
constplus1=a=> a +1;
685
695
constmult2=a=> a *2;
686
696
697
+
// bad
687
698
mult2(plus1(5)); // => 12
688
699
689
-
690
700
// good
691
-
constpipeline= (...funcs) =>
692
-
val=>funcs.reduce((a, b) =>b(a), val);
693
-
694
-
constplus1=a=> a +1;
695
-
constmult2=a=> a *2;
701
+
constpipeline= (...funcs) =>val=>funcs.reduce((a, b) =>b(a), val);
696
702
constaddThenMult=pipeline(plus1, mult2);
697
-
698
703
addThenMult(5); // => 12
699
704
```
700
705
@@ -725,13 +730,12 @@ Favor `const` over `let` and `let` over `var`.
725
730
726
731
```javascript
727
732
// bad
728
-
varobj={};
729
-
obj["foo"+"bar"] ="baz";
733
+
varme=newMap();
734
+
me.set("name", "Ben").set("country", "Belgium");
730
735
731
736
// good
732
-
constobj= {
733
-
["foo"+"bar"]:"baz"
734
-
};
737
+
constme=newMap();
738
+
me.set("name", "Ben").set("country", "Belgium");
735
739
```
736
740
737
741
### Conditions
@@ -799,7 +803,7 @@ meSize++;
799
803
meSize; // => 3
800
804
801
805
// good
802
-
constme=Map();
806
+
constme=newMap();
803
807
me.set("name", "Ben");
804
808
me.set("age", 30);
805
809
me.size; // => 2
@@ -809,7 +813,8 @@ me.size; // => 3
809
813
810
814
### Curry
811
815
812
-
Currying might have its place in other languages, but avoid it in JavaScript. It makes your code harder to read by introducing a foreign paradigm while the appropriate use cases are extremely unusual.
816
+
Currying is a powerful but foreign paradigm for many developers. Don't abuse it as its appropriate
0 commit comments