2017年5月11日木曜日

開発環境

Head First JavaScript Programming (Eric T. Freeman (著)、Elisabeth Robson (著)、O'Reilly Media)の Chapter 10.(Liberated functions - First Class Functions)の EXERCISE(No. 6618)を取り組んでみる。

EXERCISE(No. 6618)

コード(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';

let passengers = [
    {name: 'Jane Doloop', paid: true},
    {name: 'Dr. Evel', paid: true},
    {name: 'Sue Property', paid: false},
    {name: 'John Funcall', paid: true}
];

let printPassenger = (passenger) => {
    p(`name: ${passenger.name}, paid: ${passenger.paid}`);
    return false;
};

let processPassengers = (passengers, testFunction) =>
    passengers.every((passenger) => !testFunction(passenger));


let output = () => {
    processPassengers(passengers, printPassenger);
};

let clear = () => pre0.textContent = '';

btn0.onclick = output;
btn1.onclick = clear;

output();





    







						

0 コメント:

コメントを投稿