Because parseInt takes an optional second argument indicating what base to use (10 by default), and map provides its closure a second parameters indicating the index of each item in the array, which can be ignored as JS doesn't care if you call functions with the wrong number of arguments. (In fact, there's a 3rd arg too for the original array). These optional arguments interact in an unintended way so it computes things like parseInt("3", 3) which is NaN
I think in this context it is because what you suggested would pass the result of container.remove to container.stop rather than the actual function itself
is going to actually call the function and pass it's returned value (in this case, undefined) to container.stop rather than just passing the function itself to container.stop
Actually, I think we both missed the case. OP’s code doesn’t care about the value of kill() so if its a promise that takes a few seconds to complete, it doesn’t matter. However, in your refactoring, if it takes a few seconds to kill then it does matter because the promise will wait for that to complete.
That's true. A friend also pointed out that there might be issues surrounding the usage of this inside the kill() method(depending on the implementation)
no, container.stop would receive the Promise that .catch() returns. container.stop may or may not be handling promises instead of callbacks.
Another problem is that .catch() would call container.kill with the Promise object set as this. You could write container.kill.bind(container) as a workaround
Your comment I replied to didn't even include the word 'Promise' so you couldn't have said exactly that.
In your mock, kill() doesn't reference this, so it's going to work, but in a real life scenario, it would most likely use this with the assumption that it points to the container object in question, so that last line would not work. See: https://jsfiddle.net/zu6vp9yj/
52
u/PerfectionismTech Sep 16 '18
Couldn’t even be consistent and use the fat arrow syntax in both places.
13
u/lenswipe Sep 16 '18 edited Sep 16 '18
5
u/AdalwinAmillion Sep 17 '18
I FOUGHT RUNTIME ERRORS MORE FEARSOME THAN YOU!
3
u/brkmnd Sep 16 '18
And the container just stays red and lacquerish.
1
u/flarn2006 Sep 17 '18
I believe it not!
1
u/CipheredBytes Sep 17 '18
Maybe this container is invincible ...
1
u/jarfil Sep 17 '18 edited Dec 02 '23
CENSORED