Pure functions and higher-order functions

pure function

  • As long as it is the same input (actual parameter), the same output (return) must be obtained
  • Do not overwrite parameter data
  • Does not produce any side effects such as network requests, input and output devices
  • Cannot call Data.now()or Math.random()wait for impure methods
  • Redux reducerfunctions must be pure functions

higher order functions

  • 参数是函数or 返回是参数a function of
  • Common high-order functions: timer setting functions, arrays forEach()/map()/filter()/find()/bind(), Promise, etc.

おすすめ

転載: blog.csdn.net/Dax1_/article/details/126592135