Page 17 -
P. 17

copyWith: function(name, value) {
                                 var number = parseFloat(value);

                                 if (isNaN(number) || !isFinite(number))
                                   return this;

                                 if (name = = = Calc.xName)
                                   return new CalcValue(this.calc, number, this.y);


                                 if (name = = = Calc.yName)
                                   return new CalcValue(this.calc, this.x, number);

                                 return this;
                               },
                               render: function() {
                                 this.calc.render(this.result);
                               }
                             };


                             function initCalc(elem) {   calc 컴포넌트를 초기화합니다.

                               var calc =
                                 new Calc(
                                   elem.querySelector('input.calc-x-input'),
                                   elem.querySelector('input.calc-y-input'),
                                   elem.querySelector('span.calc-result')
                                 );
                               var lastValues =
                                 new CalcValue(
                                   calc,
                                   parseFloat(calc.xInput.value),
                                   parseFloat(calc.yInput.value)
                                 );


                               var handleCalcEvent =   이벤트 핸들러입니다.
                                 function handleCalcEvent(e) {
                                   var newValues = lastValues,
                                       elem = e.target;


                                   switch (elem) {
                                     case calc.xInput:
                                       newValues =
                                         lastValues.copyWith(
                                           Calc.xName,


             028




         Vue.js 코딩 공작소(본문)최종.indd   28                                                           2019-09-07   오후 8:43:25
   12   13   14   15   16   17   18   19   20   21   22