在JS中我需要在节点模块gm(我想用imageMagick而不是默认的graphicsMagick)中传递这样的参数:
var gm = require('gm').subClass({ imageMagick: true });
Run Code Online (Sandbox Code Playgroud)
我怎样才能在ES6中做到这一点?
import gm from "gm";
gm.subClass({ imageMagick: true });
Run Code Online (Sandbox Code Playgroud)
不起作用,因为gm默认为未安装的GraphicsMagick.
编写一个演示脚本来理解promises我嵌套了多个promises(使用promises.all()在then(()所有promises之后继续)然后在then()中.嵌套的promises的then()s无法解析:
var Promise = require("bluebird");
var array = [];
// push promises onto array
new Promise(function(resolve, reject) {
setTimeout(function() {
for (var i = 5 - 1; i >= 0; i--) {
array.push(returnapromise());
console.log("pushed promise number", i, "onto array");
}
resolve();
}, 300);
})
.then(function() {
new Promise.all(array).then(function() {
console.log("\nall done\n");
});
});
// function that returns a promise
var returnapromise = function() {
return new Promise(function(yolo) {
new Promise(function() {
setTimeout(function() {
console.log("async function within nested promise");
}, 200); …Run Code Online (Sandbox Code Playgroud)