网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

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
    }
}

当前标题:typescript类--学习笔记三
新闻来源:http://bjjierui.cn/article/ihpscp.html

其他资讯