javascript ES6,7,8有用的例子#javascript

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript ES6,7,8有用的例子#javascript相关的知识,希望对你有一定的参考价值。

* Object.entries() method returns an array of a given object’s own enumerable property [key, value] pairs.
var fruits = {

    apple: 10,
    orange: 20,
    grapes: 30,
    pineapple: 40

}

for (var [key, val] of Object.entries(fruits)) {

    console.log(key, val);

}
> Output:
>apple 10
>orange 20
>grapes 30
>pineapple 40

* Object.values () : You are familiar with Object.keys(). This is exactly opposite of Object.keys().
var fruits = {
  
    apple: 10,
    orange: 20,
    grapes: 30,
    pineapple: 40
  
}

var totalVegetables = Object.values(fruits).reduce((a, b) => a + b);

console.log(totalVegetables);
>Output : 100

3**3 = 27
2**2**2 = 16

class Animal {

    constructor() {

        this.name = "Lion"

    }

    age = 0;

}

That will be complied to:

    class Animal {

        constructor() {

            this.age = 0;
            this.name = "Lion";

        }

    }

Especially react developers can relate easily state! and initialProps!:

    class Animal {

        constructor() {

            this.name = "Lion"

        }

        age = 0;

        state = {

        }

        initialProps = {

        }

    }

以上是关于javascript ES6,7,8有用的例子#javascript的主要内容,如果未能解决你的问题,请参考以下文章

es6学习-8

web前端练习20----es6新语法7,生成器对象 Generator

python2.7练习小例子(二十四)

进阶学习9:ECMAScript——概述ES2015 / ES6新特性详解

es6简单介绍

Js基础知识7-Es6新增对象Map和set数据结构