forked from woowacourse/javascript-calculator
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathboard.js
More file actions
23 lines (23 loc) · 827 Bytes
/
board.js
File metadata and controls
23 lines (23 loc) · 827 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { isClear, isOperator } from "../../utils/utils.js";
class BoardImpl {
constructor({ $element, onClick }) {
this.addEvent = () => {
this.$element.addEventListener('click', ({ target }) => {
if (!(target instanceof HTMLButtonElement))
return;
const value = target.textContent;
if (isOperator(value)) {
return this.onClick({ type: 'Operator', value });
}
if (isClear(value)) {
return this.onClick({ type: 'Clear', value });
}
return this.onClick({ type: 'Number', value });
});
};
this.$element = $element;
this.onClick = onClick;
this.addEvent();
}
}
export default BoardImpl;