開発環境
- macOS Sierra - Apple (OS)
- Emacs (Text Editor)
- JavaScript (プログラミング言語)
- Safari(Web browser)
Head First JavaScript Programming (Eric T. Freeman (著)、Elisabeth Robson (著)、O'Reilly Media)の Chapter 12.(Creating objects - Advanced Object Construction)の EXERCISE(No. 7719)を取り組んでみる。
EXERCISE(No. 7719)
コード(Emacs)
HTML5
<pre id="output0"></pre> <button id="run0">run</button> <button id="clear0">clear</button> <script src="sample2.js"></script>
JavaScript
let btn0 = document.querySelector('#run0'), btn1 = document.querySelector('#clear0'), pre0 = document.querySelector('#output0'), p = (x) => pre0.textContent += x + '\n', range = (start, end, step=1) => { let result = []; for (let i = start; i < end; i += 1) { result.push(i); } return result; }; let Coffee = (roast, ounces) => { let that = {}, getSize = () => ounces === 8 ? 'small' : 12 === ounces ? 'medium' : 'larg', toString = () => `You've ordered a ${getSize()} ${roast} coffee.`; that.toString = toString; return that; }; let output = () => { let houseBlend = Coffee('House Blend', 12); p(houseBlend.toString()); let darkRoast = Coffee('Dark Roast', 16); p(darkRoast.toString()); }; let clear = () => pre0.textContent = ''; btn0.onclick = output; btn1.onclick = clear; output();
0 コメント:
コメントを投稿