es6 随笔

 记录一些学习es6中学习的新特性,挺有用,作为日后复习es6用,便于记忆。

1.变量定义let和const

  es6用let、const代替,let是定义块级作用域中的变量,const声明之后必须赋值,并且作为指针,其指向了一个内存地址

2.箭头函数()=>

  需要注意的是箭头函数里的this,总是绑定对象自身

3.函数参数默认值

  let funcs = (a,b=5) => a+b;

  

funcs(2) //7

4.Spread / Rest 操作符

  

Spread操作符:
function foo(x,y,z) {
  console.log(x,y,z);
}
let arr = [1,2,3];
foo(...arr); // 1 2 3

Rest操作符:
function foo(...args) {
  console.log(args);
}
foo( 1, 2, 3, 4, 5); // [1, 2, 3, 4, 5]

5.对象简写

  

let obj = {
   key1,
   key2,
         key3
}    

6.对象和数组解构

  

function foo() {
  return [1,2,3];
}
let [a, b, c] = foo();
console.log(a, b, c); // 1 2 3

function bar() {
  return {
    x: 4,
    y: 5,
    z: 6
  };
}
let {x: x, y: y, z: z} = bar();
console.log(x, y, z); // 4 5 6

7.`分隔符,${XXX},XXX为变量

8. set新对象

let mySet = new Set([1, 1, 2, 2, 3, 3]);

这个特性,在面试题中数组去重很有用

9.class 类

10.Promise  .then回调函数

  

转载于:https://www.cnblogs.com/var-foo-bar/p/7826804.html

你可能感兴趣的:(面试)