JS functions composed in the opposite order
问题 Starting with a simple function composition const fa = (x => (x + "a")); const fb = (x => (x + "b")); fb(fa('x')) I played around and I obtained the following code snippet which returns 'xba' instead of 'xab'. Can someone explain why? const fa = next => x => next(x + "a"); const fb = next => x => next(x + "b"); console.log(fb(fa(y => y))('x')); 回答1: Let's break this down: const _fa = fa(y => y) // _fa = x => (y => y)(x + "a") To avoid confusing the two x let's name it as x1 // _fa = x1 => (y