File tree Expand file tree Collapse file tree 1 file changed +6
-12
lines changed Expand file tree Collapse file tree 1 file changed +6
-12
lines changed Original file line number Diff line number Diff line change @@ -2401,19 +2401,13 @@ function sum(a, b) {
2401
2401
<details ><summary ><b >答案</b ></summary >
2402
2402
<p >
2403
2403
2404
- #### 答案: B
2405
-
2406
- 纯函数一种若输入参数相同,则永远会得到相同输出的函数。
2407
-
2408
- 在特定情况下,即使输入相同参数,也不能得到相同的返回值:
2404
+ #### 答案: A
2409
2405
2410
- <pre >
2411
- var a = b = {}
2412
- a[Symbol.toPrimitive] = b[Symbol.toPrimitive] = () => Math.random()
2413
- sum(a, b) // Uncertain
2414
- </pre >
2406
+ 纯函数在相同的输入值时,需产生相同的输出,其输出的结果,与输入值以外的其他隐藏信息或状态无关,也和由I/O设备产生的外部输出无关。
2407
+ 纯函数不会产生副作用。
2415
2408
2416
- 所以它不是一个纯函数。
2409
+ 纯函数与副作用的定义可参考:
2410
+ https://zh.wikipedia.org/wiki/%E5%89%AF%E4%BD%9C%E7%94%A8_(%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%A7%91%E5%AD%A6)
2417
2411
2418
2412
</p >
2419
2413
</details >
@@ -5085,4 +5079,4 @@ if (!typeof randomValue === "string") {
5085
5079
`!typeof randomValue === "string"` 总是返回false,因为我们实际上是在执行 `false === "string"`。因为条件返回的是 `false`,所以 `else` 语句中的代码块会被运行,因此打印 `Yay it' s a string! ` 。
5086
5080
5087
5081
</p>
5088
- </details>
5082
+ </details>
You can’t perform that action at this time.
0 commit comments