javascript promise not passing all arguments (using Q)

后端 未结 3 1632
半阙折子戏
半阙折子戏 2020-11-29 11:15

I am having trouble passing all arguments. My promise callback only receives one instead of three:

var asyncFunction= function(resolve) {
    setTimeout(func         


        
相关标签:
3条回答
  • 2020-11-29 11:36

    If you want to pass along multiple values, you must wrap them in another single value that you pass, such as an array or an object.

    0 讨论(0)
  • 2020-11-29 11:43

    Q promises can be resolved with only one argument - a promise stands for one single value, not for a collection of them. Put them in an array explicitly if you need multiple values. For the multiple-parameter-callbacks, you can use .spread().

    0 讨论(0)
  • 2020-11-29 11:43

    Synchronous functions return only one value, same way asynchronous should resolve with one.

    It's a bad practice to create async functions that resolve with many values. If you want to pass many values, return them in array or dict object, same as you would do if given function would be synchronous.

    0 讨论(0)
提交回复
热议问题