//ES6實現(xiàn)繼承
classPerson {
constructor(name, age) {
this.name= name;
this.age= age;
}
Show() {
return(this.name+' '+this.age);
}
}
classStudentextendsPerson {
constructor(name, age, School) {
super(name, age);
this.School= School;
}
Show() {
return(super.Show() +' '+this.School);
}
}
letme=newStudent("mochen","10","XD");
//ES5繼承
functionjicheng(parent) {
functionF(){};
F.prototype= parent;
return newF();
}
//Promise實例
functionf(par) {
return newPromise((resolve, reject) => {
//異步操作
if(true)//如果判斷條件為true,即異步執(zhí)行成功
{
resolve(參數(shù));
}else{
reject(參數(shù));
}
})
}
letmyPromise=newf(par);
myPromise(par)
.then(()=> {})//此處為異步成功時你要執(zhí)行的函數(shù)
.catch(() => {})//此處為異步失敗你要執(zhí)行的函數(shù)