我正在嘗試檢索[[PromiseValue]]Promise 的。我的函數當前返回一個 Promise,而我想要myFunction返回的值是存儲在[[PromiseValue]]返回的 Promise 中的值。這將返回一個 Promise。myFunction(){ return fetch("/api") .then(res => { return res.json(); }) .then(json => { return json; })}我試過這段代碼,但是當我在控制臺中打印數據時,它打印出正確的值,但返回的值是未定義的。myFunction(){ return fetch("/api") .then(res => { return res.json(); }) .then(json => { return json; }) .then(data => { const stringData = data.toString(); console.log(stringData); // prints the correct string return stringData; // returns undefined })}我如何讓我的函數返回存儲在[[PromiseValue]]字符串中的值?請幫幫我,謝謝!
Javascript Promises:獲取 .then 檢索 [[PromiseValue]]
HUH函數
2023-01-06 10:55:26