首页 > 其他 > 详细

系统复习--ES6新特征

时间:2020-04-20 15:17:18      阅读:68      评论:0      收藏:0      [点我收藏+]

ES6新特征

1.class(类)

ES6 引入了class(类),让JavaScript的面向对象编程变得更加简单和易于理解。

class Animal {
    // 构造函数,实例化的时候将会被调用,如果不指定,那么会有一个不带参数的默认构造函数.
    constructor(name, color) {
        this.name = name;
        this.color = color;
    }
    // toString 是原型对象上的属性
    toString() {
        console.log(name: + this.name + ,color: + this.color);
    }
}

var animal = new Animal(dog, white); //实例化Animal
animal.toString(); //name:dog,color:white

// console.log(animal.hasOwnProperty(‘name‘)); //true
// console.log(animal.hasOwnProperty(‘toString‘)); // false
// console.log(animal.__proto__.hasOwnProperty(‘toString‘)); // true

class Cat extends Animal {
    constructor(action) {
        // 子类必须要在constructor中指定super 函数,否则在新建实例的时候会报错.
        // 如果没有置顶consructor,默认带super函数的constructor将会被添加、
        super(cat, white);
        this.action = action;
    }
    toString() {
        super.toString();
    }
}

var cat = new Cat(catch)
cat.toString(); //name:dog,color:white


// 实例cat 是 Cat 和 Animal 的实例,和Es5完全一致。
// console.log(cat instanceof Cat); // true
// console.log(cat instanceof Animal); // true

2.模块化(Module)

3.箭头(Arrow)函数

箭头函数与包围它的代码共享同一个this,能帮你很好的解决this的指向问题。

4.函数参数默认值

ES6支持在定义函数的时候为其设置默认值

function foo(height = 50, color = red) {
    console.log(height) //50
    console.log(color) //red
}
foo();

5.模板字符串

6.解构赋值

7.Promise

8.let和const

 

系统复习--ES6新特征

原文:https://www.cnblogs.com/qlongbg/p/12737648.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!