官术网_书友最值得收藏!

  • Redux Quick Start Guide
  • James Lee Tao Wei Suresh Kumar Mukhiya
  • 172字
  • 2021-07-02 12:40:29

Pure functions

The most common definition of a pure function is a function that does not have side effects. This is to say that the returned value of a pure function is not affected, influenced, or changed by anything other than its input parameters. Provided the same input, the pure function always generates the same output. An example is as follows:

const sum = (a, b) => a + b;

This is an example of a pure function. Assuming that you call the function sum(6,9), the result is always 15, irrespective of the number of times that you run the function. You can be confident, if you are calling a pure function with the same input, that you are always going to get the same output, which means that the output is predictable. An example of an impure function is the following square function. In addition to returning the square of the number, the function might be updating the number in a database:

function square(number) {
updateNumberInDB(number);
return number * number;
}
主站蜘蛛池模板: 尉氏县| 木兰县| 龙泉市| 抚顺市| 阜南县| 海安县| 维西| 禄劝| 南安市| 天祝| 修水县| 通化县| 桦南县| 镇江市| 武义县| 万安县| 古交市| 阿坝县| 盐亭县| 丽水市| 郑州市| 左云县| 湟中县| 西青区| 隆德县| 平南县| 鄂州市| 千阳县| 鹿泉市| 南宁市| 视频| 吉安县| 合山市| 安达市| 玛多县| 寻乌县| 米林县| 沁水县| 龙江县| 龙胜| 斗六市|