Web/04-JavaScript基础/常见代码解读.md
2021-07-29 11:08:52 +08:00

32 lines
547 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
publish: false
---
### `callback && callback()`的含义
```javascript
callback && callback()
```
含义是如果callback存在则执行callback()函数
这个 callback 通常作为函数的参数使用举例
```javascript
function foo(callback) {
{
// do something
}
callback && callback() // 不传 callback 参数,则不会执行 callback() 函数
}
foo(); // 只执行do something中的代码
foo(callback);//callback是另一个函数将此函数传入 foo将会执行callback()
```