DINH DUONG

Typescript Get Set

May 28, 2018 - 1 minutes read

Table of content

export class Animal {
    private _name;
    get name() {
        return `It's name is ${this._name}`;
    }
    set name(name: string) {
        // DOSIME THING
        if (this.preSetName())
            this._name = name;
        throw new Error('You cannot set this property, ok mén')
    }

    private preSetName(): boolean {
        const isCallToApiandHaveAccessToSet = http.get(...) // Call from api
        return isCallToApiandHaveAccessToSet
    }
}

Back to posts

typescript
github twitter codfee email email