[Javascript]promise.then,await

promise.then,await

<apex:page >
    <html>

        <head>

        </head>

        <body>

            <script type="text/javascript">

                function resolveAfter2Seconds() {
                    return new Promise(resolve => {
                        setTimeout(() => {
                        resolve('resolved');
                        }, 2000);
                    });
                }

                const promise1 = new Promise((resolve, reject) => {
                    resolve('Success!');
                });

                async function asyncCall() {
                    console.log('calling');
                    promise1.then((value) => {
                        console.log(value);
                        // expected output: "Success!"
                    });
                    const result = await resolveAfter2Seconds();
                    console.log(result);
                    // expected output: "resolved"
                }

                asyncCall();

            </script>

        </body>

    </html>
</apex:page>

結果

投稿者: kinkun

保有資格 Salesforce Certified Platform App Builder T Salesforce Certified Platform Developer I Salesforce Certified Platform Developer II Salesforce Certified Administrator

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です