ASP. net ajax extends rciptoop

Source: Internet
Author: User
Tags hasownproperty

Namespace:
Type. registerNamespace ("MyNamespance ");
-- Register a namespace

Class:
Procedure
-- Define Constructors
-- Define members (methods, attributes, events)
-- Registration
 
Constructor
Class constructor is defined as function
It is usually used to initialize domain variables.
Private Members start with an underscore (cannot be truly encapsulated)
-- This. _ name
-- This. _ age
MyNamespace. MyClass = functin (name, age)
{
This. _ name = name;
This. _ age = age;
}

Definition method:
Prototype-based definition
-- MyNamespace. MyClass. prototype =
{
MyMethod1: function ()
{
},
MyMethod2: function ()
{
This. myMethod (); // this reserved word is indispensable
}
}
Define attributes
-- Attributes of the method starting with set _ and get _ In the object-oriented system of Microsoft AJAX Libray
-- Avoid defining write-only attributes and use a method to replace them.
MyNamespace. MyClass. prototype =
{
Get_name: function ()
{
Retrun this. _ name;
},
Set_name: funciton (value)
{
This. _ name = value;
}
}

Registration type:
MyNamespace. MyClass. registerClass ("MyNamespace. MyClass ");

Abstract class:
Classes that contain abstract methods are abstract classes.
MyNamespace. MyClass. prototype =
{
MyMthod: function ()
{
Throw Error. notImplemented ();
}
}

Inheritance:
Call the constructor of the parent class
-- Skip this step for a class without a parent class
-- A class with a parent class must call the constructor of the parent class; otherwise, the inheritance effect will be lost.


MyNamespace. MyClass = function ()
{
// Call the constructor of the parent class
MyNamespace. MyClass. initializeBase (this, [parm1,...]);
}
Provide the parent class when registering the class
Abstract members of the parent class can be directly implemented in normal mode.
The toString () method cannot be inherited.
// MyClass inheritance and MyParentClass
MyNamespace. MyClass. registerClass ("MyNamespace. Myclass", MyNamespace, MyParentClass );

Method for calling the parent class
Namespace. MyClass. prototype =
{
MyMethod: function (parm1 ,...)
{
// Call the myMethod method of the parent class
MyNamespace. MyClass. callBaseMethod (this, "myMethod", [parm1,...]);
}
}

Notes for inheritance
The toString () method cannot be inherited. Similarly, there are methods such as toLocaleString, ValueOf, and hasOwnProperty.
The principle of inheritance is to copy the method of traversing the parent class through the for loop to the subclass to achieve the inheritance effect, but the for loop cannot traverse "toString", "toLocaleString ",
"ValueOf", "hasOwnProperty", "isPrototypeOf", "propertyIsEnumerable"
Therefore, you must manually modify the functions of ASP. net ajax Library.

Solution:
Add the script in your javascript script to overwrite the functions of ASP. net ajax Library.

 

1Type. prototype. resolveInheritance = function Type $ resolveInheritance (){
2 if (arguments. length! = 0) throw Error. parameterCount ();
3
4 if (this. _ basePrototypePending ){
5 var baseType = this. _ baseType;
6
7 baseType. resolveInheritance ();
8
9 for (var memberName in baseType. prototype ){
10 var memberValue = baseType. prototype [memberName];
11 if (! This. prototype [memberName]) {
12 this. prototype [memberName] = memberValue;
13}
14}
15
16 var dontEnumMembers = ["toString", "toLocaleString ",
17 "valueOf", "hasOwnProperty", "isPrototypeOf ",
18 "propertyIsEnumerable"];
19
20 for (var I = 0; I <dontEnumMembers. length; I ++)
21 {
22 var memberName = dontEnumMembers [I];
23 if (this. prototype [memberName]! = Object. prototype [memberName])
24 {
25 continue;
26}
27
28 var memberValue = baseType. prototype [memberName];
29 if (memberValue! = Object. prototype [memberName])
30 {
31 this. prototype [memberName] = memberValue;
32}
33}
34
35 delete this. _ basePrototypePending;
36}
37}
38
39

 

 

Interface:
It is roughly the same as the class definition method.
The constructor throws an exception.
All methods throw an exception
Use the registerInterface method when registering an Interface
The interface cannot inherit from other interfaces.
Because JavaScript is a weak type language, the interface in Microsoft AJAX Library is only used as a tag to reflect the effect from some reflection methods.
MyNamespace. IMyInterface = funciton ()
{
Throw Error. notImplemented ();
}
MyNamespace. IMyInterface. prototype =
{
Method: function ()
{
Throw Error. notImplemented ();
}
}

Implementation Interface
When you use the registerClass method to register a class, you can input additional parameters to implement the interface.
 
MyNamespace. myClass. registerClass ("MyNamespace. myClass ",/** parent class can be null **/,/** interface **/,/** interface **/);

Enumeration
The enumerated value is Number.
Increase readability
It can be defined as Flag. The second parameter is true: MyNamespace. MyEnum. registerEnum ("MyNamespace. MyEnum", true );
Each enumeration has the toString and parse methods.
RegisterEnum is used for enumeration registration.
The string table of the enumerated items indicates that MyNamespace. MyEnum. toString is required (the enumerated item );
Parse usage: MyNamespace. myEnum. parse ("enumerative string ");

MyNamespace. MyEnum = function ()
{
Throw Error. notImplemented ();
}
MyNamespace. MyEnum. prototype =
{
Item1: 1,
Item2: 2,
Imte3: 3
}
MyNamespace. MyEnum. registerEnum ("MyNamespace. MyEnum ");

Reflection Method
Type. prototype

GetBaseType ()
// Return the base type of the instance.
GetInterfaces ()
// Returns an Array object that contains the list of interfaces implemented by the type.
GetName ()
// Return the instance type name.
ImplementsInterface (interface)
// Determine whether the specified interface is implemented for this type. Interface: interface to be tested
InheritsFrom (parentType)
// Determine whether this type is inherited from the specified parent type. The fully qualified name of the class whose parentType is to be tested as the base class of the current instance.
IsImplementedBy (typeInstanceVar)
// Determine whether the instance has implemented the specified interface. TypeInstanceVar tests the instance of this interface on it.
IsInstanceOfType (instance)
// Determine whether the object is of the specified type or a derived type. The object to be tested by the instance.
GetRootNamespaces ()
// Returns an Array object that contains references to all root namespaces of the client application.

 

Type. isClass (type)
// Return a value indicating whether the specified type is a class.
-- Type indicates the type to be tested.
 
Type. isInterface (type)
// Return a value indicating whether the specified type is an interface.
-- Type indicates the type to be tested.
Type. isNamespace (object)
// Return a value indicating whether the specified object is a namespace.
-- Object: the object to be tested.
 
Type. isEnum (type)
// Indicates whether the specified type is enumeration.
-- Type indicates the type to be tested.
Type. isFlags (type)
// Obtain a value indicating whether the specified type is a flag integer.
-- Type indicates the type to be tested.
Type. parse (typeName, ns)
// Return an instance of the type specified by the type name.
-- TypeName: a string that represents a fully qualified class name. It can be null.
-- Ns (optional) namespace containing the class.

Event
Define EventHandlerList object

MyNamespace. MyClass = function ()
{
This. _ events = new Sys. EventHandlerList ();

}
Add and reomve events
MyNamespace. MyClass. prototype =
{
Add_myEvent: function (handler)
{
This. _ events. addHandler ("myEvent", handler );
},
Remove_myEvent: function (handler)
{
This. _ evnets. remove ("myEvent", handler );
}
}
 
How to add a trigger event

MyNamespace. MyClass. prototype =
{
RaiseMyEvent: function (e)
{
Var handler = this. _ events. getHander ("myEvent ");
If (handler)
{
Handler (this. e );
}
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.