常用es6特性
let, const, class, extends, super, arrow functions, template string, destructuring, default, rest arguments
let声明变量只在作用域块中有效
const声明常量,不会变
class, extends, super
class声明一个对象
extends子类继承父类
super方法在子类构造器中调用,让子类指向父级,否则子类没有自己的this对象
arrow function(箭头函数)\
(参数)=>{函数主体}
template string(模板字符串插入)
通常的字符串拼接变量为:"wodemingzi"+name+"
es6可以这样`wodemingzi${name}`
用反引号标示起始,用${}包裹变量
destructuring解构?
let cat = 'ken'
let dog = 'lili'
let zoo = {cat, dog}
let dog = {type: 'animal', many: 2}
let { type, many} = dog
console.log(type, many) //animal 2
个人感觉和with很像,直接将键名拿出来就能取到值
default默认值
可以直接在函数参数设置默认值
function li(name="lijinlong"){
console,.log(name)
}
li();
let, const, class, extends, super, arrow functions, template string, destructuring, default, rest arguments
let声明变量只在作用域块中有效
const声明常量,不会变
class, extends, super
class声明一个对象
extends子类继承父类
super方法在子类构造器中调用,让子类指向父级,否则子类没有自己的this对象
自己编个小例子
class people{//创建父类
constructor(){
this.name="peoplename";
this.sex="peoplesex";
this.age="100";
},
buildpeople(who){
console.log(who+"buiold"+this.name+"sex:"+this.sex+"age:"+this.age)
}
}
let people=new people()
people.buildpeople("god")
class lijinlong extends people(){//子类继承父类
constructor(){
super();
this.name="lijinling";
this.sex="man";
this.age="24";
}
}
let lijinling = new lijinlong();
lijinling.buildpeople("parents");
arrow function(箭头函数)\
(参数)=>{函数主体}
template string(模板字符串插入)
通常的字符串拼接变量为:"wodemingzi"+name+"
es6可以这样`wodemingzi${name}`
用反引号标示起始,用${}包裹变量
destructuring解构?
let cat = 'ken'
let dog = 'lili'
let zoo = {cat, dog}
let dog = {type: 'animal', many: 2}
let { type, many} = dog
console.log(type, many) //animal 2
个人感觉和with很像,直接将键名拿出来就能取到值
default默认值
可以直接在函数参数设置默认值
function li(name="lijinlong"){
console,.log(name)
}
li();