반응형
function print(str, result){
console.log(`${str} => ${result}`);
}
// other method
function print2(str, a, b){
const result = calculater[str](a, b);
console.log(`${str} => ${result}`);
}
const calculater = {
plus: function(x, y){
return x + y;
},
minus: function(x , y){
return x - y;
},
multiple: function(x, y){
return x * y;
},
divide: function(x, y){
return x / y;
},
pow: function(x, y){
return x ** y;
}
}
console.log("let's calculate 4 and 2 :");
print('plus', calculater.plus(4, 2));
print('minus', calculater.minus(4, 2));
print('multiple', calculater.multiple(4, 2));
print('divide', calculater.divide(4, 2));
print('pow', calculater.pow(4, 2));
// other method
console.log('\nthis is the result of print2');
print2('plus', 4, 2);
print2('minus', 4, 2);
print2('multiple', 4, 2);
print2('divide', 4, 2);
print2('pow', 4, 2);
/*
============================================
let's calculate 4 and 2 :
plus => 6
minus => 2
multiple => 8
divide => 2
pow => 16
this is the result of print2
plus => 6
minus => 2
multiple => 8
divide => 2
pow => 16
*/
반응형
'Programming$ > Web Develop' 카테고리의 다른 글
[html] form submit action 주의 (0) | 2019.05.07 |
---|---|
[JavaScript] removeAttribute() (0) | 2019.05.07 |
[Python] 간단한 web server 구현 (0) | 2019.03.03 |
[.CSS] input cursor 없애기 (0) | 2019.02.26 |
[.CSS] z-index element 우선순위 (0) | 2019.02.26 |