首页 > 解决方案 > 任何设计模式都可以替换 javascript 中的 promise/then 链?

问题描述

现在我正在使用 Promise/then 来设计我的代码(类中的部分代码),如下所示:

Condition.getFromServer()
.then(ContentInfoFromServer =>
    this.foo(para)
)
.then(para =>
    this.bar(para)
)
.then(para =>
    this.jor(para)
)
.then(para =>
    this.dom(para)
)
.then(para =>
    this.pam(para)
)

但我认为它对性能不是很好。所以我想找一些东西来代替这段代码,我试过责任链。但这似乎很重。你能否建议一些好的方法来代替它。提前致谢!

标签: javascriptdesign-patterns

解决方案


推荐阅读