Javascript:从嵌套函数调用的外部方法

时间:2019-05-01 11:08:25

标签: javascript typescript ecmascript-6 ecmascript-5

我想打电话给mask = tf.boolean_mask(x_tf, x_tf < 1e-3) %timeit tf.sqrt(mask).eval() -> 341 ms ± 1.92 ms per loop (mean ± std. dev. of 7 runs, 1 loop each) ,但遇到异常。任何人都可以帮助我如何处理从嵌套函数调用的外部方法?

openSnackBar

1 个答案:

答案 0 :(得分:2)

使用ES6双箭头符号保留this范围。

export class DetailsComponent implements OnInit, OnDestroy
{
updateTodoPromise.then( fulfilled => { // <--- here
            // yay, you got a new phone
            this.openSnackBar('Task saved successfully!', 'CLOSE');
        })
        .catch( error => {  // <--- and here
            // ops, mom don't buy it
            console.log(error.message);
            this.openSnackBar('Task saved successfully!','CLOSE');
        });

    }

    public openSnackBar(full: string, full2: string) {
        this.snackBar.open(full, full2, {
            duration: 5000,
        });
    }
相关问题