快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

typescript类--学习笔记三-创新互联

typescript 类 -- 学习笔记三

class Point {
    public x: number
    public y: number
    constructor(x: number, y: number) {
        this.x = x
        this.y = y
    }
    public getPosition() {
        return `${this.x} ${this.y}`
    }
}

const point = new Point(1, 2)

class Parent {
    public name: string
    constructor(name: string) {
        this.name = name
    }
}

class Child extends Parent {
    constructor(name: string) {
        super(name)
    }
}

// public 公共

// private 私有的

// protected 受保护

class Parent1 {
    // private age: number
    protected age: number
    protected constructor(age: number) {
        this.age = age
    }
    protected getAge() {
        return this.age
    }
}

class Child1 extends Parent1 {
    constructor(age: number) {
        super(age)
    }
}

// readonly
class UserInfo {
    public readonly name: string
    constructor(name: string) {
        this.name = name
    }
}

class A {
    constructor(public name: string) {}
}

class Parent3 {
    public static getAge() {
        return Parent3.age
    }
    private static age: number = 18
    constructor() {}
}

class Info {
    public name: string
    public age?: number
    private _infoStr: string
    constructor(name: string, age?: number, public sex?: string) {
        this.name = name
        this.age = age
    }
    get infoStr() {
        return this._infoStr
    }
    set infoStr(value) {
        // console.log(`setter: ${value}`)
        this._infoStr = value
    }
}

// 抽象类,abstract 类不能创建的实例对象。
abstract class People {
    constructor(public name: string) {}
    public abstract printName(): void
}

class Man extends People {
    constructor(name: string) {
        super(name)
        this.name = name
    }
    public printName() {
        console.log(this.name)
    }
}
const m = new Man('lison')
m.printName()

abstract class People1 {
    public abstract _name: string
    abstract get insideName(): string
    abstract set insideName(value: string)
}
class P extends People1 {
    public _name: string
    public insideName: string
}

class People3 {
    constructor(public name: string) {}
}
let p2: People3 = new People3('lison')
class Animal {
    constructor(public name: string) {}
}
p2 = new Animal('haha')

// 接口
interface FoodInterface {
    type: string
}
class FoodClass implements FoodInterface {
    public type: string
}

class A1 {
    protected name: string
}
interface I extends A1 {}

class B extends A1 implements I {
    public name: string
}

const create = (c: new() => T): T => {
    return new c()
}
class Infos {
    public age: number
    constructor() {
        this.age = 18
    }
}

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。

创新互联是一家专业提供吉林企业网站建设,专注与做网站、网站建设、成都h5网站建设、小程序制作等业务。10年已为吉林众多企业、政府机构等服务。创新互联专业的建站公司优惠进行中。
分享题目:typescript类--学习笔记三-创新互联
网址分享:http://6mz.cn/article/dojcje.html

其他资讯