ES6 的Class方式內部聲明的方法,等同於function定義的原型方法

類的實現方式,ES6 的Class方式內部聲明的方法,等同於function定義的原型方法

//構造函數方法
function A(name,age)
{
this.name=name;
this.age=age;
}
A.protype.test=function(){
console.log('this is protype function test')
}
//類方式
class B{
constructor(name,age){
this.age=age;
this.name=name;
}
test(){
console.log('this is a class method')
}
}
測試方法 var b=new B();
查看b對象的原型裏面存在test方法

相關文章
相關標籤/搜索