我正在自学JavaScript并且在处理promise内部的函数返回值时遇到了麻烦。我的代码大致是这样的:
foobar = function(x,y){
//code that doesn't matter
return promiseFunction(
function(results){
console.log("promise completed")
console.log(output)
return output;}
function(err){throw error;});
console.log(foobar('1','2'));
这会打印出
这段文本。
undefined
promise completed
what I want the result to be
我刚接触异步编程,不确定自己做错了什么。
return
一个promise。promiseFunction
是否返回$.ajax
的结果?如果您还没有使用jQuery,最好使用其他库。您如何在没有HTML的情况下执行脚本?在这种环境中可能有某种形式的import
或require
。 - Bergi