ES6新增常见特性
var let const 区别 1.var声明变量会发生变量提升,let、const不会发生变量提升 2.var允许重复声明变量,let不可以 3.const声明变量不可以被改变 用反引号创建字符串,其中可用${'变量'} console.log(`your name is ${name}`); 与普通函数的区别 1、书写上用=>代替了function 2、普通函数的this指向window 而ES6箭头函数里面的this指向定义时的那个对象 而不是运行时的那个对象 //普通函数 var test = function(x){ return x+2; } 使用箭头函数: var test = x=>x+2; ES6中添加了对类的支持,引入了class关键字 以前编写一个构造函数(类) function Pad(color){ this.color = color; } 现在的写法跟Java更接近了 class Iphone{ constructor(color, size){ this.color = color; this.size = size; } playgame(){ //............. } toString(){ return `这台手机的颜色是${this.color} 屏幕大小是${this.size}`; } } 我们定义了一个类,名字叫Iphone