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方法

相关文章
相关标签/搜索