ES5~ES6的学习

转载至大佬吴迪98的文章ES5/6新特性_阮一峰es5-CSDN博客

ES5

1. 严格模式

<script>
       "use strict";
       var aa = 1;
</script>

支持严格模式的浏览器:
Internet Explorer 10 +、Firefox 4+、 Chrome 13+、 Safari 5.1+、 Opera 12+

严格模式下:

  1. 变量必须先声名后赋值
  2. 不允许直接使用以0开头的八进制表示,如果要表示八进制数字,以 0o 为前缀
  3. 如果直接使用函数名调用函数,则函数体中的this为undefined。

ES6

1. 箭头函数(lambda表达式) 

箭头函数的 this 会一直往上一层找,直到找到 this 对象

 <script>
       const aa = () => {
        console.log(this)
           console.log(1)
       }
       aa();
</script>

 

 2. 解构赋值

<script>
        //对象解构
       const a = {name:'hhh', age: 1}
       console.log(a)
       //age 和 name 会自动映射对象属性名的值 
       const{age, name} = a
       //等效于
       //const age = a.age
       //const name = a.name
       console.log('age=', age, 'name=', name)//age= 1 name= hhh

       //数组解构
       const arr = ['hhh', 1]
       const [param1, param2] = arr
       console.log(param1,param2) // hhh 1
</script>

3. ...

//...组装数组
    const arr1 = ['a', 'b', 'c']
    const arr2 = [...arr1 , 'd', 'e', 'f']
    console.log(arr2) // ['a', 'b', 'c', , 'd', 'e', 'f']
//拆分数组
    const arr3 = ['a', 'b', 'c', 'd', 'e', 'f']
    const [a, ...b] = arr3
    console.log(a) // a
    console.log(b) // ['b', 'c', 'd', 'e', 'f']

 4. Promise

Promise总结-CSDN博客

5. Import 和 Export

// 引入部分
import dva from 'dva';

// 引入部分
import { connect } from 'dva';
import { Link, Route } from 'dva/router';

// 引入全部并作为 github 对象
import * as github from './services/github';

// 导出默认
export default App
// 部分导出,需 import { App } from './file';引入
export class App extend Component {};

6. 新增 Map 和 Set 

6.1 Map

set(key, val)  

get(key)

delete(key)

clear()

entries()

has()

keys()

values()

 6.2 Set

和 Map 差不多

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值