Đang chuẩn bị liên kết để tải về tài liệu:
Test Driven JavaScript Development- P9

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

Test Driven JavaScript Development- P9:This book is about programming JavaScript for the real world, using the techniques and workflow suggested by Test-Driven Development. It is about gaining confidence in your code through test coverage, and gaining the ability to fearlessly refactor and organically evolve your code base. It is about writing modular and testable code. It is about writing JavaScript that works in a wide variety of environments and that doesn’t get in your user’s way. | 7.5 Object Composition and Mixins 153 accept an optional properties argument. We will discuss this method further in Chapter 8 ECMAScript 5th Edition. 7.5.2 The tddj s.extend Method Often we want to borrow behavior from one or more other objects to build the functionality we re after. We ve seen this a couple of times already. Remember the arguments object It acts roughly like an array but it is not a true array and as such lacks certain properties we might be interested in. The arguments object does however possess the most important aspects of an array the length property and numerical indexes as property names. These two aspects are enough for most methods on Array.prototype to consider arguments an object that walks like a duck swims like a duck and quacks like a duck and therefore is a duck or rather an array . This means that we can borrow methods from Array.prototype by calling them with arguments as this as seen in Listing 7.50. Listing 7.50 Borrowing from Array.prototype test arguments should borrow from Array.prototype function function addToArray var args Array.prototype.slice.call arguments var arr args.shift return arr.concat args var result addToArray 1 2 3 assertEquals 1 2 3 result The example borrows the slice function and calls it on the arguments object. Because we don t give it any other arguments it will return the whole array but the trick is now we ve effectively converted arguments to an array on which we can call the usual array methods. Remember in Chapter 5 Functions we illustrated implicit binding of this by copying a function from one object to another. Doing so causes both objects to share the same function object so it s a memory efficient way to share behavior. Listing 7.51 shows an example. Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. From the Library of WoweBook.Com 154 Objects and Prototypal Inheritance Listing 7.51 Borrowing explicitly test arguments should borrow explicitly from Array.prototype .

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.