TAILIEUCHUNG - ASP.NET AJAX in Action phần 3

Lớp HumanResources chứa một trong những phương pháp, GetEmployeeCount, trong đó có tên khoa như một tham số. Nó sử dụng một tuyên bố chuyển đổi đơn giản để lấy số lượng nhân viên trong bộ phận. (Để giữ cho những điều đơn giản, chúng tôi hardcoded | Working with objects 81 Understanding closures and dealing with them can be difficult at first because the most used object-oriented languages don t support them. But closures have interesting applications for example the method illustrated in chapter 2 in section is an application of closures. If you program in .NET using C then you may have heard of anonymous methods which can t be called closures but that implement a similar technique. NOTE If you want to know more about C anonymous methods browse to http en-us library . So far we ve demonstrated that JavaScript functions are powerful objects but you can do much more. For example you can use functions to create custom objects as you ll see in the next section. Creating custom objects In section you saw how JavaScript objects can be created as dictionaries with name and value pairs. Each pair represents a property of the object and the value of the property. This approach may be less comfortable for developers acquainted with the mechanisms of class-based object-oriented languages. In such languages you typically specify the structure of an object in a class and then you create instances of the class using the new operator. If you want to use a similar approach in JavaScript it s possible to define a function and use it in conjunction with the new operator to create custom objects. In this case the function is called the constructor and it s used to define the properties of the new object. Following this approach listing shows how to declare the constructor for a Cat object. Listing The constructor for a Cat object function Cat 0 A JavaScript function acts as a constructor when you use it together with the new operator. The following statement creates a new object using the Cat function as the constructor var cat new Cat The new operator creates a new object and invokes the constructor. In the body of the .

TỪ KHÓA LIÊN QUAN
Đã 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.