timsensor
V2EX  ›  问与答

typescript 里,怎样用类实例作为参数调用类成员

  •  
  •   timsensor · Mar 5, 2018 · 1565 views
    This topic created in 3003 days ago, the information mentioned may be changed or developed.

    小弟常用 C++和 C#,最近学 ts,遇到了以下问题:

    class Fruit {
            private _weight: number;
            get weight() {
                return this._weight;
            }
            set weight(v: number) {
                this._weight = v;
            }
            bite(): void {
                this._weight - 0.1;
            }
        }
    

    有没有方法可以做到类似下面伪代码的作用

    let obj = new Fruit();
    Fruit.prototype.bite(obj);
    let rest = Fruit.prototype.weight(obj);
    
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1354 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 17:03 · PVG 01:03 · LAX 10:03 · JFK 13:03
    ♥ Do have faith in what you're doing.