Practical prototype and scipt.aculo.us part 51

Practical prototype and part 51: 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. | CHAPTER 13 Prototype As a Platform Prototype s features exemplify the functionality that distinguishes frameworks from libraries. It provides more than just shortcuts it gives you new ways to structure your code. In this chapter we ll look at some of these tactics and patterns. We ll move beyond an explanation of what the framework does and into higher-level strategies for solving problems. Some of these are specific code patterns to simplify common tasks others make code more modular and adaptable. Using Code Patterns A script written atop Prototype has a particular style to call it flair would perhaps be overindulgent . It s peppered with the time-saving patterns and terse syntactic shortcuts that are Prototype s trademark. I m calling these code patterns but please don t treat them as copy-and-paste sections of code. They re more like recipes use them as a guide but feel free to modify an ingredient or two as you see fit. Staying DRY with Inheritance and Mixins Prototype s class-based inheritance model lets you build a deep inheritance tree. Subclasses can call all the methods of their parents even those that have been overridden. Prototype itself uses inheritance with the Ajax classes. The simplest of the three serves as a superclass for both and . uses inheritance even more liberally. For instance all core effects inherit from an abstract class called . Any Prototype or class can be subclassed by the user and customized. Inheritance is a simple solution for code sharing but it isn t always the best solution. Sometimes several classes need to share code but don t lend themselves to any sort of hierarchical relationship. 297 298 CHAPTER 13 PROTOTYPE AS A PLATFORM That s where mixins come in. Mixins are sets of methods that can be added to any class independent of any sort of inheritance. A class can have only one parent class multiple inheritance is not supported but it .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã 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.