開発環境
- macOS Sierra - Apple (OS)
- Emacs (Text Editor)
- JavaScript (プログラミング言語)
- Safari(Web browser)
Head First JavaScript Programming (Eric T. Freeman (著)、Elisabeth Robson (著)、O'Reilly Media)の Chapter 9.(Handling events - Asynchronous Coding)の WHO DOES WHAT?(No. 5911)を取り組んでみる。
WHO DOES WHAT?(No. 5911)
コード(Emacs)
HTML5
<pre id="output0"></pre> <button id="run0">run</button> <button id="clear0">clear</button> <script src="sample1.js"></script>
JavaScript
let btn0 = document.querySelector('#run0'), btn1 = document.querySelector('#clear0'), pre0 = document.querySelector('#output0'), p = (x) => pre0.textContent += x + '\n'; let b0 = document.querySelector('body'); b0.onclick = (event) => { for (let prop in event) { p(`${prop}: ${event[prop]}`); } p( ['target', 'type', 'timeStamp', 'clientX', 'clientY', 'touches'] .map((prop) => `event['${prop}'] = ${event[prop]}`) .join('\n') ); }; let output = () => { b0.click(); }; let clear = (event) => { event.stopPropagation(); pre0.textContent = ''; }; btn0.onclick = output; btn1.onclick = clear; output();
0 コメント:
コメントを投稿