在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
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); }*/
|
请发表评论