Typescript

  • 添加了类型注解等类型的功能
    • `let num: number = 10`
    • 添加了interface定义, abstract, private, public, protected
  • 学习案例

// 写在立即执行函数中否则 let 可能会报错

(function() {

   

// 非常类似 Java  C#

let numnumber = 10

let isMarriedboolean = false

let namestring = 'Jackson'

interface IWalk {

    /**

     * walk

     */

    walk(): void;

}

abstract class AnimalBase {

    private _namestring;

    private _agenumber;

    constructor(namestringagenumber) {

        this._name = name

        this._age = age

    }

    abstract say(): void;

    get name(): string {

        return this._name

    }

    set name(name) {

        this._name = name

    }

    get age(): number {

        return this._age

    }

    set age(age) {

        this._age = age

    }

}

   

class Dog extends AnimalBase implements IWalk {

    say(): void {

        console.log('Woof!')

    }

    walk() {

        console.log('Jump!')

    }

}

let dogDog = new Dog('Lily'1)

console.log(dog.name)

console.log(name)

dog.say()

let walkIWalk = new Dog('Jack'2)

walk.walk()

let dogsArray<Dog> = []

dogs.push(dog)

dogs.push(new Dog('Tom'2))

console.log(dogs)

let myTuple: [numberbooleanstring] = [numisMarriedname]

console.log(myTuple)

})()

posted @ 2021-06-01 11:52  gogogo11  阅读(39)  评论(0编辑  收藏  举报