我对承诺的使用感到困惑,特别是它的数据操作方式(将值从一个块传递到另一个块)和异常处理(出现错误)。我正在努力学习一种正确的方法来使用承诺和处理错误,比如
Error: A caught error.
at promiseTwo()
at promiseOne()
at subprocess()
at mainprocess()
以下是我在实施这些建议时所做的两次尝试:
尝试1:笨手笨脚,嵌套得很深,错误是不存在的。
var subprocess = () => {
return new Promise((resolve, reject) =>
我尝试的第一件事是将一个调用放在另一个回调函数中,如下所示:
var url1 = "json_example1.json";
var url2 = "json_example2.json";
var callback1 = function (response1) {$.get(url2,callback2);}
var callback2 = function (response2) {console.log(response1,response2)}
第二个回调函数甚至没有运行!
我也尝试过像这样使用when..this
var url1 = "
昨天我参加了一个面试,我得到了如下的编程挑战:
// 3. Coding challenge.
// The goal is to make function1/function2 to work only when the constructor has finished its async operations.
// You CAN'T change the notifyUrls function. Imagine it's a 3th party library you don't have control on.
// CAN'T CHANGE TH