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

Tham khảo tài liệu 'phát triển javascript - part 37', 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 Comet Client 333 The test fails as dispatch was not called. To fix this we need to parse the responseText as JSON and call the method from within the success callback of the request. A very naive implementation can be seen in Listing . Listing Naive success callback to the poller function connect if throw new TypeError Provide client URL if success function xhr .bind this At this point I am expecting this test to still fail in at least a few browsers. As we discussed in Chapter 8 ECMAScript 5th Edition EcmaScript5 specifies a JSON object. However it is not yet widely implemented least of all in older browsers such as Internet Explorer 6. Still the tests pass. What s happening is that JsTestDriver is already using Douglas Crockford s JSON parser internally and because it does not namespace its dependencies in the test runner our test accidentally works because the environment loads our dependencies for us. Hopefully this issue with JsTest-Driver will be worked out but until then we need to keep this in the back of our heads. The proper solution is of course to add . from in lib . I mentioned that the above implementation was naive. A successful response from the server does not imply valid JSON. What do you suppose happens when the test in Listing runs Listing Expecting badly formed data not to be dispatched test should not dispatch badly formed data function my url stubFn Download from 334 Streaming Data with Ajax and Comet 200 OK assertFalse Furthermore if we expect the server to return JSON data it would probably be a good idea to indicate as much by sending the right Accept header with the request. Separating Concerns The current implementation has a code smell something that doesn t feel .

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.