Web/03-JavaScript基础/30-常见代码解读.md
2019-06-15 21:00:07 +08:00

28 lines
527 B
Markdown
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.

### `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()
```