開発環境
- macOS Sierra - Apple (OS)
- Emacs (Text Editor)
- JavaScript (プログラミング言語)
- Safari(Web browser)
Head First JavaScript Programming (Eric T. Freeman (著)、Elisabeth Robson (著)、O'Reilly Media)の Chapter 5.(A trip to Objectville - Understanding Objects)、Putting it all together… の EXERCISE(No. 2764) を取り組んでみる。
EXERCISE(No. 2764)
コード(Emacs)
HTML5
<button id="run0">run</button><button id="clear0">clear</button> <pre id="output0"></pre> <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 car = { make: 'Chevy', model: 'Bel Air', year: 1957, color: 'red', passengers: 2, convetible: false, mileage: 1021, }; let output = () => { Object.keys(car).forEach((k) => { p(`${k}: ${car[k]}`); }); }; btn0.onclick = output; btn1.onclick = () => { pre0.textContent = ''; }; output();
0 コメント:
コメントを投稿