码迷,mamicode.com
首页 > 其他好文 > 详细

es6 - filter for-chrome

时间:2018-07-31 15:34:28      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:numbers   str   ons   square   ict   add   for   col   new   

 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

标签:numbers   str   ons   square   ict   add   for   col   new   

原文地址:https://www.cnblogs.com/cisum/p/9395294.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!