This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //非同期を制御するために一般的に使用されるコールバックパターン | |
| setTimeout(function(){ | |
| echo_arg('A'); | |
| //前の処理のイベントハンドラ内に次に実行したい処理を記述する | |
| setTimeout(function(){ | |
| echo_arg('B'); | |
| setTimeout(function(){ | |
| echo_arg('c'); | |
| },1000); | |
| },2000); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //async/await は Promise の糖衣構文(Syntax-Sugar)です。 | |
| //Promise の処理をメソッドチェーンではなく、以下のように記述することができます。 | |
| (async ()=>{ | |
| echo_arg(await p_setTimeout('A',3000)); | |
| echo_arg(await p_setTimeout('B',2000)); | |
| echo_arg(await p_setTimeout('C',1000)); | |
| })(); | |
| function p_setTimeout(arg, delayLenght){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //※アロー関数を使用しています。(Internet Explorer では動作しません) | |
| //()=>{} は function(){} と同じ意味です。 | |
| //Promise を使用した記述 | |
| //以下のように非同期処理をメソッドチェーンで記述できる | |
| //new Promise(()=>{1回目の処理}).then(2回めの処理,エラー処理).then(3回めの処理) | |
| p_setTimeout('A', 3000) | |
| .then((arg)=>{ | |
| echo_arg(arg); | |
| return p_setTimeout('B',2000);}) | |
| .then((arg)=>{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html lang="ja"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>Document</title> | |
| </head> | |
| <body> | |
| <div id="display"></div> | |
| <button id="btnStart">次へ</button> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html xmlns="http://www.w3.org/1999/xhtml"> | |
| <head> | |
| <meta http-equiv="Content-Type" lang="ja" content="text/html;charset=utf-8"/> | |
| <title></title> | |
| <script> | |
| //innerText をサポートしない Web ブラウザと共通で使用するための | |
| //setText 関数を定義 | |
| function setAlter_innerText(element) { | |
| if (element.innerText) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*Web コンテンツを開発するための Node.js 簡易 Web サーバー サンプル*/ | |
| //Web サーバーが Listen する IP アドレス | |
| var LISTEN_IP = '127.0.0.1'; | |
| //Web サーバーが Listen する ポート | |
| var LISTEN_PORT = 8086; | |
| //ファイル名が指定されない場合に返す既定のファイル名 | |
| var DEFAULT_FILE = "default.html"; | |
| var http = require('http'), |
NewerOlder