zoukankan      html  css  js  c++  java
  • es6

    1.新的变量声明方式 let/const

    let局部作用域,没有声明提前。

    const 来声明一个值不会被改变的变量,也可以称之为常量。

    var 如果重复声明,后面会覆盖前面,现在let不允许重复声明,

    2.箭头函数

    es6里面的箭头函数除了写法不同外,比较需要注意的点就在不能用this,也不能用arguements:

    var box = document.getElementById("box");
            // box.onclick = function(){
            //     fun();
            // }
            // function fun(){
            //     this.style.background = '#f00'; 
            // }
            box.onclick = () => {
                this.style.background = '#f00'; 
            }
    
            // function fun(){
            //     console.log(arguments);
            // }
            var fun = () => {
                console.log(arguments);
            }
    
            fun(1,2,3,4)
    
            // 注意的地方
            // 1.不能用this,箭头函数中的this指向window
            // 2.不能使用arguments

    3.原型

    在ES6以前,必须有类和构造,在ES6以前是没有类的概念,构造函数即是构造,也是类、到了ES6,就将其完全划分开了:

    // class 类
            // constructor  构造函数
            class Person{   //
                constructor(name,age){    //构造
                    this.name = name;
                    this.age = age;
                }
                showName(){
                    return this.name;
                }
                showAge(){
                    return this.age;
                }
            }
            var person = new Person("jack",18);
            // var person2 = new Person("mack",20);
            // console.log(person.showName === person2.showName)
            // console.log(person.constructor === Person)
    
    
            // 继承
            // class Student extends Person{};
            // var student = new Student("mack",50);
            // console.log(student);
    
    
    
            class Student extends Person{
                constructor(name,age,pid){
                    // this.name = name;
                    // this.age = age;
                    super(name,age);
                    this.pid = pid;
                }
                showPid(){
                    return this.pid;
                }
            }
    
            var student = new Student("mack",50,"00001");
            console.log(student);

    4.字符串的拼接

    以前我们字符串拼接" "+ +" ",而且进行换行等操作会异常麻烦,不换行在一行内又很难看清。

    es6里面字符串拼接``就省去了很多麻烦,可以进行换行操作且没有影响,中间添加变量直接用${}不用"+"连接,修改起来也很方便。

    str += `<ul> 
                <li>${uname}</li> 
                <li>nan</li> 
                <li>18</li> 
                <li>150123456878</li> 
                <li>xxx@xxx.com</li> 
            </ul>`
  • 相关阅读:
    洛谷 P2048 [NOI2010]超级钢琴(优先队列,RMQ)
    洛谷P1074 靶形数独(跳舞链)
    洛谷P1337 [JSOI2004]平衡点 / 吊打XXX(模拟退火)
    洛谷P4003 无限之环(费用流)
    洛谷P3264 [JLOI2015]管道连接(斯坦纳树)
    洛谷P3190 [HNOI2007]神奇游乐园(插头dp)
    洛谷P3272 [SCOI2011]地板(插头dp)
    常用的端口配置
    Win7+Eclipse+Hadoop2.6.4开发环境搭建
    Windows10+eclipse+hadoop2.7.1环境配置+wordcount-折腾笔记
  • 原文地址:https://www.cnblogs.com/tangdiying/p/10477399.html
Copyright © 2011-2022 走看看