RE: RE: JavaScript开发笔记
You are viewing a single comment's thread from:

RE: JavaScript开发笔记

Words
78
Reading
1 min
Listen
Play
7M

阮一峰ES6

ES5 只有两种声明变量的方法:var命令和function命令。ES6 除了添加let和const命令,后面章节还会提到,另外两种声明变量的方法:import命令和class命令。所以,ES6 一共有 6 种声明变量的方法。

1let  var 
,
(for)let
{
  let num = 20;
}
console.log(num);  // unm is not defined

2const 
const MAX = 10;

3` `, ${a}
let a = 123
let str = `
这是另一行文本${a}
这是再一行文本`

4
  const add = (num1,num2) => {
      return num1*num2
  }
  
  const add = (num1, num2) => return num1*num2

  
  const add = function(num1, num2){
    return num1*num2
  }

5arguments, this使thisthisthis
thisshow: function (){} --> show(){}

6...
   let arr = [5,6]
   console.log([1,3,5,...arr])
7
  const arr = [1, 2, 3];
  const [a, b, c] = arr;
8
   show: function (){} --> show(){}
9
  import export export default   

  export const sum = (x, y) => x + y
  import { sum } from 'aa'

  export default (x, y) => x + y
  import x form 'aa'  //可以取任意名字

10----ES5
    function Animal(name, age) {
        this.name = name;
        this.age = age;
    }
    //构造方法
    Animal.prototype.showname = function () {
        console.log(111,this.name)
    }
    var dog = new Animal()
    dog.name = "zhangsan";
    

  *****//ES6的新写法
  class Animal{
    constructor(name, age){  //构造器,初始化属性
        this.name = name;
        this.age = age;
    }      //此处一定是无符号的
    showName(){    //构造方法
        console.log(123, this.name);
    }
  }
  var dog = new Animal("zhansan22", 19);
  dog.showName();
@lemooljiang: 阮一峰ES6 ES5 | Ecency