小编Mat*_*att的帖子

如何将Promise.all与对象一起用作输入

我一直在为我自己使用的小型2D游戏库工作,我遇到了一些问题.库中有一个名为loadGame的特定函数,它将依赖信息作为​​输入(资源文件和要执行的脚本列表).这是一个例子.

loadGame({
    "root" : "/source/folder/for/game/",

    "resources" : {
        "soundEffect" : "audio/sound.mp3",
        "someImage" : "images/something.png",
        "someJSON" : "json/map.json"
    },

    "scripts" : [
        "js/helperScript.js",
        "js/mainScript.js"
    ]
})
Run Code Online (Sandbox Code Playgroud)

资源中的每个项目都有一个密钥,游戏使用该密钥来访问该特定资源.loadGame函数将资源转换为promises对象.

问题是它试图使用Promises.all来检查它们何时准备就绪,但是Promise.all只接受迭代作为输入 - 所以像我所拥有的对象是不可能的.

所以我尝试将对象转换为数组,这很有效,除了每个资源只是数组中的一个元素,并且没有用于标识它们的键.

这是loadGame的代码:

var loadGame = function (game) {
    return new Promise(function (fulfill, reject) {
        // the root folder for the game
        var root = game.root || '';

        // these are the types of files that can be loaded
        // getImage, getAudio, and getJSON are defined elsewhere in my code - they …
Run Code Online (Sandbox Code Playgroud)

javascript asynchronous promise

22
推荐指数
6
解决办法
3万
查看次数

如何使用文件内容作为命令行参数 Windows

在 Bash shell 中,我可以写

some_command $(< some_file)
Run Code Online (Sandbox Code Playgroud)

将 some_file 的内容作为命令行参数传递给 some_command。我怎样才能最好地在 Windows 上完成同样的事情,最好使用内置命令/语法?

编辑:澄清一下, some_file 中的任何形式的空格都应该被视为参数分隔符,就像我的 Bash 示例中的情况一样。特别是,即使 some_file 有多行,这也需要工作。

windows file command-line-arguments

5
推荐指数
1
解决办法
1322
查看次数