zoukankan      html  css  js  c++  java
  • 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'




  • 相关阅读:
    java多线程
    golang编码转换
    golang csv,xls,xlsx
    golang 资源
    electron安装
    Ubuntu系统下面软件安装更新命令
    golang代码执行顺序
    datatables使用
    Echarts柱形图颜色设置
    golang chan 超时
  • 原文地址:https://www.cnblogs.com/dianzan/p/8530692.html
Copyright © 2011-2022 走看看