TAILIEUCHUNG - Phát triển Javascript - part 22

Tham khảo tài liệu 'phát triển javascript - part 22', 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ả | Do Not Make Assumptions 183 Do Not Make Assumptions Do not make assumptions is perhaps the most important rule of unobtrusive JavaScript. It sums up most aspects of clean JavaScript in a single phrasing. In this section we will go over the most common assumptions and why they make it challenging to write robust scripts for the web. Don t Assume You Are Alone Never assume that scripts run in isolation. This applies to application developers as much as library authors because most websites today use code from at least one external source. Assuming scripts run in isolation makes running them alongside scripts we don t control harder. For the last few years all the sites I ve worked on use at least one external analytics script and most of these scripts use as a last resort. has a nasty side-effect of wiping the entire document if used after the DOM has fully loaded. This means that asynchronously loading content invoking the offending code will cause the site s analytics script to effectively break it completely. I ve seen maintenance developers break down in tears as they realize what is causing their site to fail and it ain t a pretty sight. How to Avoid The less we contribute to the global environment the less we will depend on it. Keeping our global footprint small reduces chances of conflicts with other scripts. Techniques to minimize global impact were described in Chapter 6 Applied Functions and Closures. Besides keeping the number of global objects low we need to watch out for other forms of global state such as assigning to or using the aforementioned . Don t Assume Markup Is Correct When separating concerns we should strive to keep as much markup in the document as possible. In practice this equates to using the fallback solution as a basis for the scripted solution as much as possible. However this also means that scripts are no longer in complete control of markup so we .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.