Phát triển Javascript - part 46

Tham khảo tài liệu 'phát triển javascript - part 46', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | The Message Form 423 Refactoring Extracting the Common Parts We will take a small detour by refactoring the user form controller. We will extract a formController object from which both of the controllers can inherit. Step one is adding the new object as Listing shows. Save it in src form . Listing Extracting a form controller function if typeof tddjs undefined return var dom var chat chat if dom return function setView element js-chat var handler this element submit handler element setView setView To build this file I simply copied the entire user form controller and stripped out anything not related to setting the view. At this point you re probably wondering where are the tests . It s a valid question. However we are not adding or modifying behavior we re merely moving around parts of the implementation. The existing tests should suffice in telling us if the refactoring is successful at least for the documented tested behavior which is the only behavior we re concerned about at this point. Step two is making the user form controller use the new generic controller. We can achieve this by popping it in as the form controller s prototype object as seen in Listing . Download from 424 TDD and DOM Manipulation The Chat Client Listing Changing userFormController s ancestry Running the tests confirms that this change does not interfere with the existing behavior of the user form controller. Next up we remove userFormController s own setview implementation. The expectation is that it should now inherit this method from formController thus the tests should still pass. Running them confirms that they do. Before the refactoring can be considered done we should .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
5    97    1    22-05-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.