在RHS表达式中使用LHS变量-它如何工作?

时间:2019-01-23 07:26:06

标签: typescript

我正在编写一个简单的Process类,并提供了以下代码(这只是摘录,不是完整的类定义):

    class Process {
    private waitingContext?: {
        promise: Promise<number>,
        resolve: (exitCode: number) => void,
        reject: (err: any) => void
    };
    wait(): Promise<number> {
        if (this.waitingContext)
            return this.waitingContext.promise;
        const promise = new Promise<number>(
            (resolve: (exitCode: number) => void, reject: (err: any) => void) => {
                this.waitingContext = {promise, resolve, reject};
        });
        return promise;
    }
    }

令我困惑的是,在构造对象和进行赋值之前,如何引用新创建的变量promise。用JavaScript正常吗?

0 个答案:

没有答案