Mastering JavaScript Functional Programming
上QQ阅读APP看书,第一时间看更新

Testing the solution manually

We can run a simple test:

const squeak = a => console.log(a, " squeak!!");
squeak("original"); // "original squeak!!"
squeak("original"); // "original squeak!!"
squeak("original"); // "original squeak!!"

const squeakOnce = once(squeak);
squeakOnce("only once"); // "only once squeak!!"
squeakOnce("only once"); // no output
squeakOnce("only once"); // no output

Check out the results at CodePen, or see Figure 2.2:

Figure 2.2 - Testing our once() higher-order function