首页 > 其他 > 详细

ES6 新特性(2015)

时间:2021-05-14 16:21:55      阅读:25      评论:0      收藏:0      [点我收藏+]

ES6 新特性(2015)

es5发布时间:2009-11

es6发布时间:2015-6

两个版本之间的时间跨度很大,所以ES6中的特性比较多。

下面几个是常用的:

  • 模块化
  • 箭头函数
  • 函数参数默认值
  • 模板字符串
  • 解构赋值
  • 延展操作符
  • 对象属性简写
  • Promise
  • Let与Const

1、类(class)

  对熟悉Java,object-c,c#等纯面向对象语言的开发者来说,都会对class有一种特殊的情怀。ES6引入了calss(类),让JavaScript的面向对象变成变得更加简单和易于理解。

class Animal {
    constructor(name, color) {
        this.name = name;
        this.color = color;
    }
    toString() {
        console.log(‘name:‘ + this.name + ‘,color:‘ + this.color);
    }
}
var animal = new Animal(‘dog‘, ‘white‘);
animal.toString();

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

class Cat extends Animal{
     constructor(action){
           //如果没有置顶constructor,默认带super函数的constructor将会被添加
           super(‘cat‘,‘white‘);
           this.action = action;
     }
     toString(){
            console.log(super.toString());
     }
}

var cat = new Cat(‘catch‘)
cat.toString();

console.log(cat instanceof Cat);
cosole.log(cat instanceof Animal);

  

 

  

 

ES6 新特性(2015)

原文:https://www.cnblogs.com/meiyanstar/p/14768198.html

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