javascript - 在 promise 中更直接地使用函数

标签 javascript parse-platform parse-cloud-code

有没有一种表达方式:

    imagePFFileFromUrl(exampUrl) // (returns a promise)
    .then(function(xxx))
        // that syntax gives you the results of the
        // imagePFFileFromUrl inside the variable xxx.
        // I then use it in another function which
        // returns another promise...
        {
        return saveImageFile(xxx, anotherArgument) // (returns a promise)
        })
    .then(function(savedPFFile)

更像这样..

    imagePFFileFromUrl(exampUrl)
    .then(saveImageFile(...the results from imagePFFileFromUrl ...))
    .then(function(savedPFFile)

什么时候使用 promise?

最佳答案

您的 .then() 需要有 1 或 2 个回调函数。如果有 1,它会接受 promise 的已解决值。如果有两个,则第二个采用 promise 的拒绝值。所以,不,你不能做你想做的事。


这是一个很好的example带有两个参数的模式,请注意 return synchUsers

关于javascript - 在 promise 中更直接地使用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32766623/

相关文章:

javascript - 查找数组是否包含用户

javascript - 菜单 mouseenter mouseleave click

javascript - 两列中的三个 div - 等高

java - com.parse.ParseException : bolts. ExecutorException:执行器抛出异常

javascript - 解析云代码获取指针

javascript - 如何将 Parse.User 数据保存为数组指针

asp.net - 如何以编程方式单击 asp.net 中的 EIT Lightbox 超链接

c# - XMPP C# 交互

ios - 在类方法中设置属性变量

javascript - 通过Parse.com云代码取消Stripe计划,查询问题