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

Tham khảo tài liệu 'phát triển javascript - part 41', 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ả | Event Emitters 373 Listing Expecting chatRoom to be event emitter testCase exports chatRoom should be event emitter function test We can pass this test by popping in as chatRoom s prototype as seen in Listing . Listing chatRoom inheriting from . var EventEmitter require events .EventEmitter . var chatRoom function user message . function id . Note that because V8 fully supports ECMAScript 5 s we could have used property descriptors to add the methods as well as seen in Listing . Listing chatRoom defined with property descriptors var chatRoom addMessage value function user message . getMessagesSince value function id . Download from 374 Server-Side JavaScript with At this point the property descriptors don t provide anything we have a documented need for . the ability to override default property attribute values so we ll avoid the added indentation and stick with the simple assignments in Listing . Next up we make sure that addMessage emits an event. Listing shows the test. Listing Expecting addMessage to emit a message event testCase exports . should emit message event function test var message message function m message m cjno msg .then function m m message To pass this test we need to place a call to emit right before we resolve the promise as seen in Listing . Listing Emitting a message event function user message callback var promise new Promise function . if err . message data data else err true Download from Event Emitters 375 .bind this .

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.