Đang chuẩn bị liên kết để tải về tài liệu:
Practical prototype and scipt.aculo.us part 10

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

Practical prototype and scipt.aculo.us part 10: The information in this book is distributed on an "as is" basis, without warranty Although every pre-caution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work. | 42 CHAPTER 3 COLLECTIONS OR NEVER WRITE A FOR LOOP AGAIN var obj obj.constructor - Object obj name Statue of Liberty constructor Frédéric Bartholdi obj.constructor - Frédéric Bartholdi In this example a built-in property constructor that has special meaning in JavaScript is being shadowed by a property of the same name that we assign on the object instance. Similar collisions can occur with toString valueOf and other built-in properties. The safety of any arbitrary key cannot be guaranteed. These might seem like edge cases but key safety is especially important when you re building a hash in which the key names depend on user input or on some other means that isn t planned beforehand by the developer. The Object.prototype Problem As we briefly covered in Chapter 2 JavaScript suffers from a flaw caused by two of its features stepping on one another. In theory we can define properties on Object.prototype and have them propagate to every instance of Object. Unfortunately when properties are enumerated in a for.in loop anything that s been defined on Object.prototype will get picked up. Object.prototype.each function iterator for var i in this iterator i this i var obj name Statue of Liberty constructor Frédéric Bartholdi obj.each console.log pass the key and value as arguments to console.log name Statue of Liberty constructor Frédéric Bartholdi each function iterator for var i in this iterator i this i CHAPTER 3 COLLECTIONS OR NEVER WRITE A FOR LOOP AGAIN 43 Regrettably there s no way to suppress this behavior. We could get around it by avoiding ordinary for.in loops altogether wrapping code around them that ensures we enumerate only properties that exist on the instance but then we ve only solved the problem for our own scripts. Web pages often pull in scripts from various sources some of which may be unaware of each other s existence. We can t expect all these scripts to boil the ocean just to make our lives a little easier. The Solution There s a way around all .

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.