開発環境
- OS X Mavericks - Apple(OS)
- Safari, Firefox + Firebug, Google Chrome(Webプラウザ、プラグイン)
- BBEdit - Bare Bones Software, Inc. (GUI) , Emacs (CUI) (Text Editor)
- JavaScript (プログラミング言語)
Head First JavaScript Programming (Eric T. Freeman (著)、 Elisabeth Robson (著)、 O'Reilly Media )のChapter 11(Serious functions: Anonymous Functions, Scope and Closures)、EXERCISE(p.500)を解いてみる。
EXERCISE(p.500)
コード(BBEdit, Emacs)
var makePassword = function (password) {
return function (passwordGuess) {
return passwordGuess === password;
};
},
multN = function (n) {
return function (result) {
return result * n;
};
},
makeCounter = function () {
var count = 0;
return {
increment: function () {
count += 1;
return count;
}
};
},
p1 = makePassword("pass1"),
p2 = makePassword("pass2"),
mult5 = multN(5),
mult10 = multN(10),
c1 = makeCounter(),
c2 = makeCounter();
print(p1('pass1'));
print(p1('pass2'));
print(p2('pass1'));
print(p2('pass2'));
print(mult5(15));
print(mult5(20));
print(mult10(15));
print(mult10(20));
print(c1.increment())
print(c1.increment());
print(c2.increment());
print(c2.increment());
0 コメント:
コメントを投稿