我该如何得到一个变量的字符串表示形式,就像在 console.log()
输出时所显示的那样?
例如:
const myFunc = async () => 'my string';
ret = myFunc();
console.log(ret); // Promise { 'my string' }
stringRepresentation = ret.someMethod(); // is there a method or some other way?
console.assert(stringRepresentation === "Promise { 'my string' }");
我主要关注在Node.js中运行它(但也好奇在浏览器中运行是否可能)。
Promise { 'my string' }
可能是其中一个特殊的检查器。因此,对于你的问题,大多数情况下的答案是“不”。 - deceze