var calculator = (function() { function add(a, b) { return a + b; } function subtract(a, b) { return a - b; } function multiply(a, b) { return a * b; } return { add: add, subtract: subtract, multiply: multiply }; })(); console.log(calculator.add(2, 3)); // 5 console.log(calculator.subtract(5, 2)); // 3 console.log(calculator.multiply(4, 3)); // 12 var myFunctions = { add: function(a, b) { return a + b; }, subtract: function(a, b) { return a - b; }, multiply: function(a, b) { return a * b; } }; // 사용 예제 console.log(myFunctions.add(2, 3)); // 5 console.log(myFunctions.subtract(5, 2)); // 3 console.log(myFunctions.multiply(4, 3)); // 12
'MY' 카테고리의 다른 글
서비스 테스트 (0) | 2024.08.03 |
---|---|
maria (0) | 2023.11.19 |
참고용 링크 (0) | 2023.09.10 |
thread processing (0) | 2023.08.21 |
code style (0) | 2023.08.05 |