类中的成员分为: 静态成员 和 实例成员;
静态成员包含了:静态属性 和 静态方法;
实例成员包含了:实例属性 和 实例方法;
通过修饰符 static 来定义成员为 静态成员 还是 实例成员;
静态成员 使用 类名 来调用,实例成员 使用 this 来调用;
静态成员 只能通过类来调用,不会被实例继承,实例成员可以通过实例调用。
const {ccclass, property} = cc._decorator;
@ccclass
export default class Test extends cc.Component {
@property(cc.Label)
label: cc.Label = null;
@property
text: string = 'hello';
static testNum:number = 10;
static testFun():void{
console.log('testFun');
}
start () {
}
}
网友评论