ES6 学习1

https://www.jianshu.com/p/287e0bb867ae

1,let表示变量、const表示常量。let和const都是块级作用域。一个在函数内部,一个在代码块内部;

 const name = 'lux'

 name = 'joe' //再次赋值此时会报错

 

,2,

    //es5 
    var name = 'lux'
    console.log('hello' + name)
    //es6
    const name = 'lux'
    console.log(`hello ${name}`) //hello lux

3,箭头函数
  • 不需要function关键字来创建函数
  • 省略return关键字
  • 继承当前上下文的 this 关键字
//例如:
    [1,2,3].map( x => x + 1 )
    
//等同于:
    [1,2,3].map((function(x){
        return x + 1
    }).bind(this))

4.拓展的对象功能

ES5我们对于对象都是以键值对的形式书写,是有可能出现键值对重名的。例如:

    function people(name, age) {
        return {
            name: name,
            age: age
        };
    }

键值对重名,ES6可以简写如下:

    function people(name, age) {
        return {
            name,
            age
        };
    }

5.更方便的数据访问--解构

//对象 const people = { name: 'lux', age: 20 }
const { name, age } = people
console.log(`${name} --- ${age}`)
//数组 const color = ['red', 'blue']
const [first, second] = color
console.log(first) //'red'
console.log(second) //'blue'




转载于:https://www.cnblogs.com/dianzan/p/8530692.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值