Đang chuẩn bị liên kết để tải về tài liệu:
Defining Members

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

Xác định thành viên Không phải tất cả các thành viên lớp được tạo ra bằng nhau. Sử dụng các từ khoá đặc biệt, các thành viên có thể được cấu hình trong nhiều cách khác nhau, cho phép bạn chỉ định cách thành viên được truy cập và phạm vi ảnh hưởng của nó. | Defining Members Not all class members are created equal. Using special keywords members can be configured in various ways allowing you to specify how the member is accessed and the scope of its influence. Next we ll discuss what this means and how you can use this functionality when creating class members. Public and Private Members By default all members of a class its properties and methods are public. This means that the property or methods of that class can be accessed by instances of that class. Look again at our State class definition class State var statePopulation Number function State Constructor function setPopulation num Number statePopulation num num .05 function getPopulation Number return statePopulation The members in this class statePopulation setPopulation and getPopulation are all publicly accessible by instances of the class. For example the following script northCarolina.statePopulation 8000000 shows us setting the value of statePopulation directly. As mentioned in the preceding section while this property is used to hold a numeric value representing the state s population it s better to use getter and setter methods to get and set the value which our class definition has been set up to do. In other words statePopulation should be a variable that cannot be directly accessed from outside the class definition. To make this change you use the private and public keywords to indicate each member s access in a class class State private var statePopulation Number function State Constructor public function setPopulation num Number statePopulation num num .05 public function getPopulation Number return statePopulation statePopulation has been declared as a private member of the class. As a result only code within the class definition itself such as the setPopulation and getPopulation methods can access it directly. Attempting to access it from an instance in the following way northCarolina.statePopulation 8000000 results in an error. Any property or .

TÀI LIỆU LIÊN QUAN