Egret 类的创建和继承--TypeScript

该博客为转载内容,转载自https://www.cnblogs.com/allyh/p/10558071.html ,涉及JavaScript相关知识。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

class test extends egret.DisplayObjectContainer {
	/**
	 * 类的创建
	 */
	//属性
	name: string;
	age: number;
	ts: test;
	//可传参的构造方法
	public constructor(name: string, age: number) {
		super();
		this.name = name;
		this.age = age;
	}
	//普通函数
	public print() {
		return this.name + ":" + this.age;
	}
	public check() {
		//使用:利用对象调用函数的执行
		let tc = new test("sss", 12);
		alert(tc.print());
		//2

	}

}
let tc = new test("sss", 12);
alert(tc.print());
/**
 * 类的继承
 */
class Person {
	name: string;
	age: number;
	public constructor() { }
	//普通函数
	public print() {
		return this.name + ":" + this.age;
	}
	public check() {
		//使用

	}
}
class Student extends Person {
	school: string;
	public print() {
		return this.name + ":" + this.age + ":" + this.school;
	}
}
//调用
var s = new Student();
s.name = "ss";
s.age = 900;
s.school = "aa";
alert(s.print());
//或者通过构造函数直接传参,就不需要对象做赋值操作
//Person
/*
public constructor(name: string, age: number) {   
	this.name = name;
	this.age = age;
}
//student
public constructor(school:string) {   
	this.school = school;
	super("aaa",100);
}*/

  

转载于:https://www.cnblogs.com/allyh/p/10558071.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值