2017年4月29日土曜日

開発環境

Head First JavaScript Programming (Eric T. Freeman (著)、Elisabeth Robson (著)、O'Reilly Media)の Chapter 8.(Building an app - Bringing it All Together)の EXERCISE(No. 4937)を取り組んでみる。

EXERCISE(No. 4937)

コード(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 view = {
    displayMessage : (msg) => msg,
    displayHit: () => 'Hit',
    displayMiss: () => 'Miss'
};

let output = () => {
    p(view.displayMessage('Message'));
    p(view.displayHit());
    p(view.displayMiss());
};

btn0.onclick = output;
btn1.onclick = () => pre0.textContent = '';

output();





    







						

0 コメント:

コメントを投稿