类方法总结

类包含的内容:静态方法、静态属性、私有方法、私有属性、公有方法、公有属性
// 类
class Point{
// 私有属性
#privateDemo = 100;
// 静态属性
static staticDemo = 200;
// 公共属性
publicDemo= 300;
// 构造函数
constructor (x,y) {
this.x = x;
this.y = y;
}
// 私有方法
#privateFunction() {
console.log(this)
}
// 静态方法
static privateFunction () {
console.log(this)
}
// 公有方法
publicFunction() {
console.log(this)
}
}
// 实例化对象
const objectDemo = new Point(10,20) ;
// 静态属性、静态方法的调用方式
Point.staticDemo; // 200
Point.pri

类方法总结最先出现在Python成神之路

版权声明:
作者:siwei
链接:https://www.techfm.club/p/24958.html
来源:TechFM
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>