私は基本的にJavaScriptを使用する方法を知っていても、JavaScriptのasync function
が技術的に何であるかを理解しようとしています。ES7非同期機能と約束の技術的な違いは?
async function asyncFunc() {
// nop
}
var fooPromise = new Promise(r => setTimeout(r, 1));
console.clear();
console.log("typeof asyncFunc is", typeof asyncFunc); // function
console.log("typeof asyncFunc.next is", typeof asyncFunc.next); // undefined
console.log("typeof asyncFunc.then is", typeof asyncFunc.then); // undefined
console.log("typeof fooPromise is", typeof fooPromise); // object
console.log("typeof fooPromise.next is", typeof fooPromise.next); // undefined
console.log("typeof fooPromise.then is", typeof fooPromise.then); // function
はまだ、それは間違いなく可能です:
多く紹介非同期に/ async
機能は基本的には約束ですが、それは明らかにケース(Babel6-transpiled codeでない少なくとも)ではないことを信じて作る待ちます例えば、await fooPromise()
のように、await
に約束してください。
は、それ自身のもの
async funtion
ですとawait
は単に約束と互換性のですか?実行中(Babel互換の方法で)簡単な
function
とasync function
を区別する方法はありますか?
ありがとうございます。したがって、本質的に、 'asyncFunc'はPromiseではありませんが、' asyncFunc() 'は - または他の言葉でです:' typeof asyncFunc()。then == "function" ' –
これはまさに正しいものです。 –