19. function performCommandHardcoded(command) {
var result;
switch (command.type)
{
case 'notify':
result = notify(command.message);
break;
case 'join':
result = changeView(command.target);
break;
default:
alert(command.type);
}
return result;
}
TAKAMURA'Narimichi'/'第'4'回'Topotal'輪読会@2015/03/18 19
28. 命令型プログラミングとの比較
// 命令型プログラミング
var result = 0;
for(var n = 1; n <= 10; n++) {
result = result + n;
}
// 関数型プログラミング
var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
var plus = function(a, b) {
return (a + b);
};
var result = _.reduce(numbers, plus);
TAKAMURA'Narimichi'/'第'4'回'Topotal'輪読会@2015/03/18 28