我正在使用包含函数getNouns的WordPos包,例如getNouns(text,callback)。
wordpos.getNouns('The angry bear chased the frightened little squirrel.',
console.log)
// [ 'bear', 'squirrel', 'little', 'chased' ]
我想写一个数组的承诺,而不是记录它,并没有任何运气。有什么建议吗?
答案 0 :(得分:1)
你为什么不这样做
wordpos.getNouns('The angry bear chased the frightened little squirrel.', result => {
const array = result;
// do stuff with `array`
})
答案 1 :(得分:1)
您必须使用Promise
包装此函数。
function getNounsPromise(string) {
return new Promise((resolve, reject) => {
wordpos.getNouns(string, resolve);
});
}
// usage:
getNounsPromise('The angry bear chased the frightened little squirrel.')
.then(result => console.log(result)); // [ 'bear', 'squirrel', 'little', 'chased' ]