es6习惯

常用es6特性
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();


 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值