ES6

2018-11-18  本文已影响0人  致自己_cb38

1、如果浏览器不支持ES6,可以在线解析JS代码。

https://babeljs.io/repl/ #
https://google.github.io/traceur-compiler/demo/repl.html#

2、块级作用域:{} 变量及函数的生效空间

补充:
全局作用域:定义于函数外部
局部作用域:定义于函数内部

3、let 用于定义变量。没有变量的提升功能。在前面会形成一个暂时性死区。不能重复申明。

4、const 定义常量 :不变的量。比如PI

5、解构:等号两边结构相同

let obj = {
        name:"limazi",
        age:56,
        height:121,
        weight:1000
    };
let {name,age:sui,height,weight} = obj;
console.log(name,sui,height,weight)

6、字符串

let a = 'magua';
let html = `
        sdnfl
        sdfnj
        fsdnjk
        fsdnjk
        sdfnj${a}adg
        bc
        `; //sdnflsdfnjfsdnjkfsdnjksdfnj(magua)adgbc
let a = [1,2,3,5,6]
console.log(a.includes(9)) //false
'x'.padStart(5, 'ab') // 'ababx'
'x'.padStart(4, 'ab') // 'abax'

'x'.padEnd(5, 'ab') // 'xabab'

7、箭头函数

s.onclick = ()=>{
        let sum = 0;
        for(let i=1;i<=100;i++){
            sum+=i;
        }
        alert(sum);
    }
let show = (a,b)=>a+b;
console.log(new show(1,2));

8、forEach 遍历数组,每一个元素单独处理

//val 指数组的每一项的值
//index 索引
//arr 数组本身
//没有返回值
arr.forEach(function(val,index,arr){
        val.onclick = ()=>{
            alert(this);
        }
    });

补充:

9、promise
http://es6.ruanyifeng.com/#docs/promise

10、reduce
https://www.jianshu.com/p/3ab871b3a4f2

上一篇 下一篇

猜你喜欢

热点阅读