class Person{
// 类公有变量
static classStaticField = "classStaticField";
// 类私有变量
static #classPrivateField = "classPrivateField";
// 实例变量
instance_Value =2;
// 私有属性
#private_value = 10;
constructor(){ // 构造方法
// 实例变量
this.name = "jadeshu";
this.age = 25;
this.instanceFunc = function(){
console.log("实例方法");
}
}
// 原型方法 prototype.get_name
get_name() {
return this.name;
}
// 原型方法 prototype.get_age
get_age() {
return this.age;
}
// 类静态方法
// 静态方法如果包含this关键字,这个this指的是类,而不是实例。
// 父类的静态方法,可以被子类继承。
static sum(a, b) {
console.log(a+b);
}
// 属性 [属于prototype.prop]
get prop() {
return 'getter';
}
set prop(value) {
console.log('setter: '+value);
}
};
// Person.class_data = "classdata";
p = new Person();
console.log(Person);
console.log(p);
十三 ES6 class用法
猜你喜欢
转载自blog.csdn.net/jadeshu/article/details/103748976
今日推荐
周排行