【问题标题】:How to write proxy function over funciton?如何在函数上编写代理函数?
【发布时间】:2022-08-19 03:28:45
【问题描述】:

有一个类有几个方法。其中之一:

drawGeojson(layerid: string, geojsonObject) {
     this.ngZone.run(() => {}
}

如何重构代码 - 以便您可以根据要求使用包装器执行方法主体

 this.ngZone.run(() => {}

没有它?

    标签: javascript typescript


    【解决方案1】:

    如果你想有条件地执行

    this.ngZone.run(() => {})
    

    您可以向您的方法添加一个附加参数,并取决于它是否执行。

    drawGeojson(layerid: string, geojsonObject: any, execute: boolean) {
         // some code here.
         execute && this.ngZone.run(() => {})
    }
    

    【讨论】:

    • 那很好,我必须在所有方法中都写这个条件,而不是 DRY 原则
    猜你喜欢
    • 2011-01-08
    • 2018-09-12
    • 2011-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多