NumCalculator.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
  2. import _createClass from "@babel/runtime/helpers/esm/createClass";
  3. import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
  4. import _inherits from "@babel/runtime/helpers/esm/inherits";
  5. import _createSuper from "@babel/runtime/helpers/esm/createSuper";
  6. import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
  7. import AbstractCalculator from "./calculator";
  8. var NumCalculator = /*#__PURE__*/function (_AbstractCalculator) {
  9. _inherits(NumCalculator, _AbstractCalculator);
  10. var _super = _createSuper(NumCalculator);
  11. function NumCalculator(num) {
  12. var _this;
  13. _classCallCheck(this, NumCalculator);
  14. _this = _super.call(this);
  15. _defineProperty(_assertThisInitialized(_this), "result", 0);
  16. if (num instanceof NumCalculator) {
  17. _this.result = num.result;
  18. } else if (typeof num === 'number') {
  19. _this.result = num;
  20. }
  21. return _this;
  22. }
  23. _createClass(NumCalculator, [{
  24. key: "add",
  25. value: function add(num) {
  26. if (num instanceof NumCalculator) {
  27. this.result += num.result;
  28. } else if (typeof num === 'number') {
  29. this.result += num;
  30. }
  31. return this;
  32. }
  33. }, {
  34. key: "sub",
  35. value: function sub(num) {
  36. if (num instanceof NumCalculator) {
  37. this.result -= num.result;
  38. } else if (typeof num === 'number') {
  39. this.result -= num;
  40. }
  41. return this;
  42. }
  43. }, {
  44. key: "mul",
  45. value: function mul(num) {
  46. if (num instanceof NumCalculator) {
  47. this.result *= num.result;
  48. } else if (typeof num === 'number') {
  49. this.result *= num;
  50. }
  51. return this;
  52. }
  53. }, {
  54. key: "div",
  55. value: function div(num) {
  56. if (num instanceof NumCalculator) {
  57. this.result /= num.result;
  58. } else if (typeof num === 'number') {
  59. this.result /= num;
  60. }
  61. return this;
  62. }
  63. }, {
  64. key: "equal",
  65. value: function equal() {
  66. return this.result;
  67. }
  68. }]);
  69. return NumCalculator;
  70. }(AbstractCalculator);
  71. export default NumCalculator;