es6 - filter for-chrome

Posted cisum

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了es6 - filter for-chrome相关的知识,希望对你有一定的参考价值。

 1 // #####################################################################
 2 ‘use strict‘;
 3 let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9];
 4 
 5 
 6 // 除去取余2的 - es6
 7 let es5OddNumbers = numbers.filter(function (number) {
 8     return number % 2;
 9 });
10 console.log(es5OddNumbers);
11 
12 //  除去取余2的 - es6 - 第二种写法
13 let es6OddNumbers = numbers.filter(number => number % 2);
14 console.log(es6OddNumbers);
15 
16 
17 
18 // 和es5不一样的函数返参
19 let square = x => x * x;
20 console.log(square(10));
21 
22 // let add = (形参1,形参2,...)
23 let add = (a, b) => a + b;
24 console.log(add(3, 4));
25 
26 // 数组对象
27 let developers = [{ name: ‘Rob‘ }, { name: ‘Jake‘ }];
28 // 回调拿出name
29 let es5Output = developers.map(function (developer) {
30     return developer.name;
31 });
32 console.log(es5Output);
33 
34 let es6Output = developers.map(developer => developer.name);
35 console.log(es6Output);
36 
37 
38 
39 // es5 倒计时
40 function CounterES5() {
41     this.seconds = 0;
42     window.setInterval(function () {
43         this.seconds++;
44     }.bind(this), 1000); // or }.bind(this), 1000) and skip that = this
45 }
46 var counterA = new CounterES5();
47 window.setTimeout(function () {
48     console.log(counterA.seconds);
49 }, 1200);
50 
51 // es6倒计时
52 function CounterES6() {
53     this.seconds = 0;
54     window.setInterval(() => this.seconds++, 1000);
55 }
56 
57 let counterB = new CounterES6();
58 window.setTimeout(() => console.log(counterB.seconds), 1200);

 

以上是关于es6 - filter for-chrome的主要内容,如果未能解决你的问题,请参考以下文章

es6中filter的使用

es6 filter() 数组过滤方法总结

ES6 - 一条代码实现数组去重

ES6 Map遍历filter()筛选对象

ES6的过滤器方法:filter()

es6 filter的使用