ES6特性
类
javascript
lass Person{
constructor(name) {
this.name = '小明';
}
console() {
console.log(this.name);
}
}
const man = new Man('小明');
man.console(); // 小明
模块化
js代码
javascript
// 模块 变量
export let a= 3;
// 模块 方法
export function b(){
console.log("hello")
}
引入
javascript
<script type="module">
import * as m1 from "./src/js/m1.js"
console.log(m1)
</script>
箭头函数
javascript
const func = (a, b) => a + b;
func(1, 2); // 3
函数参数默认值
javascript
function fn(name= "小明"){ // ...}
模板字符串
javascript
const age= 12;
const str = `my age is ${age}`;
解构赋值
javascript
let a = 1, b= 2;
[a, b] = [b, a]; // a 2 b 1
延展操作符
javascript
let a=[1,2,3];
let b=[3,4,5];
let c = [...a,...b]
console.log(c)
对象属性简写
javascript
const name='小米',
const obj = { name };
Promise
javascript
Promise.resolve().then(() => { console.log(2); });
console.log(1);
// 先打印 1 ,再打印 2
ES7特性
Array.prototype.includes()
javascript
[1].includes(1); // true
指数操作符
javascript
2**10; // 1024
ES8特性
async/await
javascript
async getData(){
const res = await api.getTableData(); // await 异步任务
// do something
}
Object.values()
javascript
Object.values({a: 1, b: 2, c: 3}); // [1, 2, 3]