1 2 3 4 5 6 7 8 9 10 11 12 13 14 | const y = new Set([ 10 , 20 , 30 ]); const z = new Set([ 7 , 8 , 9 ]); [ 1 , 2 , 3 , 4 ].forEach(y.add, z); // oops you added to z instead console.log([...y]); console.log([...z]); // can't fault those who prefer this. I mean this line, not javascript's this :D [ 1 , 2 , 3 , 4 ].forEach(Set.prototype.add, y); console.log([...y]); console.log( '---' ); console.log([...z]); |
Wish ESLint has a warning for passing callback like in line 4
[10, 20, 30] [7, 8, 9, 1, 2, 3, 4] --- [10, 20, 30, 1, 2, 3, 4] [7, 8, 9, 1, 2, 3, 4]
No comments:
Post a Comment