1字符串新增方法
模板字符串
${變量}
?``? ? `解決之前字符串連接要多次拼接的問題
新增方法? startsWith('http') 查找字符串開頭是否包括
endsWith('.com')? 查找字符串結(jié)束是否包括
includes('') 查找字符串中是否包含
repeat()? 參數(shù)重復(fù)的次數(shù)
trimStart()消除頭部空格? (es2019新增)
trimEnd()消除尾部空格(es2019新增)
---------------------------------------------------
class 對(duì)象
函數(shù)聲明? fn1 function(){ console.log(111)}
函數(shù)表達(dá)式? let fn=function(){ console.log(111)}
class man={
constructor(){? //默認(rèn)函數(shù) 在對(duì)象創(chuàng)建時(shí)自動(dòng)調(diào)用
}
}
static? 關(guān)鍵字? (私有方法)
(只有當(dāng)前原型才可以執(zhí)行該方法)
(this指向當(dāng)前function不是當(dāng)前的對(duì)象)
(不可以被繼承)
class man{
constructor(name,age){this.name=name;this.age=age}
getName(){console.log(this.name)}
static getAge(){console.log(this.age)}? ?//this指function
}//不可繼承static? ?this指向function? ?只有原型才能調(diào)用該私有函數(shù)? (原型可以調(diào)用靜態(tài)方法 比如static? 實(shí)例才可以調(diào)用非靜態(tài)方法)
extends 繼承
class supperman? extends man{
constructor(){
super() //繼承父類的構(gòu)造函數(shù)? 并且把構(gòu)造的原型指向子類
//代碼等同于? man.prototype.constructor.call(this)
}
}
super對(duì)象指的就是父級(jí) 可以用super對(duì)象調(diào)用 父級(jí)的靜態(tài)方法
class supperman extends man{
constructor(){
super()}
fngetage(){? ?super.getAge()}? ?//利用super對(duì)象獲得父級(jí)的static方法 getAge
}
------------------
可以通過 set? get方法來(lái)監(jiān)聽賦值、讀取操作
class? num{
constructor(valuezhi){this.valuezhi=valuezhi}
get getValue(){? if(typeof(this.valuezhi)!="number"){return "啦啦啦"}}
set setValue(val){
if(typeof(val)!="string"){ this.valuezhi="非字符串"}
else{this.valuezhi=val}
}
}
let numb=new num();
numb.setValue='123';
console.log(numb.zhi)? //字符串123
console.log(numb.getValue)? //啦啦啦