前端培训文档(3.2.1)

前端培训文档(3.2.1)


​​​​​​​JS规范

<h3>1. 解构赋值</h3> <pre><code>当需要使用对象的多个属性时,请使用解构赋值</code></pre> <pre><code class="language-javascript"> function getFullName ({ firstName, lastName }) { return `${firstName} ${lastName}` } </code></pre> <p>当需要使用数组的多个值时,请同样使用解构赋值</p> <pre><code class="language-javascript">const [first, second] = arr </code></pre> <p>函数需要回传多个值时,请使用对象的解构,而不是数组的解构</p> <pre><code class="language-javascript"> function doSomething () { return { top, right, bottom, left } } // 此时不需要考虑数据的顺序 const { top, left } = doSomething() </code></pre> <h3>2. 函数</h3> <p>不要更改函数参数的值</p> <pre><code class="language-javaScript"> // bad function test (opts) { opts = opts || {} } // good function test (opts = {}) { // ... } </code></pre> <h3>3.模块</h3> <p>使用标准的 ES6 模块语法 import 和 export</p> <pre><code class="language-javascript"> // bad const util = require('./util') module.exports = util // good import Util from './util' export default Util // better import { Util } from './util' export default Util </code></pre>

页面列表

ITEM_HTML