[ASP.net AJAX] Introduction to methods of function objects and type classes

Source: Internet
Author: User
Tags array object extend functions implement interface net first row
Ajax|asp.net| objects

The last time we had a general understanding of JavaScript Microsoft AJAX Library Because of the temporary things, not to join the case is a bit abstract, this time will certainly through some cases more intuitive to asp.net the AJAX script Library a very important class type. This class provides some reflection methods for extending object-oriented programming, through which we can register similar. NET (such as namespaces, classes, enumerations, and so on) basic types. This type class inherits from window is a global type and does not belong to any namespace. Now let's look at some of the basic methods in type and how to implement some of the methods ...
Before we know the type class, we first look at an important object, which is the function object. A function object is an internal object of JavaScript, such as date objects (dates), array objects (array), character objects (String), and (Object,regexp,math,error, etc.). You can instantiate an object by using new. In addition to our common JavaScript-affirming functions, we can construct our function objects in the following ways: Var myfunction=new function (arguments,statement). Since I'm not very familiar with the script, I'm not quite aware of prototype (though I've heard that by giving out a prototype object to indicate the type of object you want to create, and then creating more objects of the same type with the method of this prototype object, the original model pattern belongs to the object creation pattern). However, after my simple test, if the function is prototype extension can be declared by new to the object and then reference him, you can call the function directly. (method or function). If you use Function.uname directly to extend this uname you can only call it through Function.uname, which reminds me of the static method in. NET (c#:static; Vb:share), with these we look at several objects in ASP.net ajax that extend to function:
[Copy this Code] CODE:
Function.__typename= "Function";
Function.createcallback=function (b,a) {
return function () {
var e=arguments.length;
if (e>0) {
var d=[];
for (Var c=0;cD[C]=ARGUMENTS[C];
D[e]=a;
Return b.apply (THIS,D)
}
Return B.call (This,a)
}
};
Function.createdelegate=function (a,b) {
return function () {
Return b.apply (a,arguments)
}
};
Function.emptyfunction=function.emptymethod=function () {};
From the above we can see that the function extends an attribute (__typename) and several methods (we can see it as. NET, if you use the new Function (), and then you get "undefined"; maybe this is the most basic thing about JavaScript, but I've never used this object to write a script, nor have I learned JavaScript in a systematic, So don't laugh at me oh: I am learning ...), I also found a relatively rare call/apply in the above; the caller,callee,call,apply concept of a comprehensive understanding of JavaScript in << > has a more detailed introduction. If I'm not mistaken: Function.createcallback ("callback Method", "callback argument") is related to the callback; Function.createdelegate ("Object usually with this", "Method executed"), that is, the proxy method created through Function.createdelegate inherits the B method, thus completing the entire agent process (not knowing if it is correct!). ); Function.emptyfunction/function.emptymethod should be prepared for interfaces and virtual functions.
The type object inherits the function object and is further extended by the function object, where we do not discuss the type implementation process, and we look at some of the important methods in the type today. There are a total of 22 methods in type, and we'll introduce each one individually:
. [Prototype] Type.callBaseMethod (instance,name,basearguments)
Description
This function mainly calls the methods in the base function, equivalent to base in C #, which is only used when inheriting functions.
Parameters:
Instance: The current instance of the base function that will be invoked, usually with this;
Name: The names of the base functions that will be invoked, represented by strings;
Basearguments: The arguments of the base function that will be invoked.
. [Prototype] Type.getbasemethod (Instance,name)
Description
Reference to a method instance of a base function, if you want to invoke a method through the Function.call function, this will be your choice, but I think the difference between the last function and the previous one is not very big and confusing.
Parameters:
Instance: In this function seems not to be called, the implementation of the last function to get the function through this function, possibly this parameter is 1 of the instance parameter reserved, I also do not understand why they do so, master free master of the truth!
Name: Of course, is the names of the methods you want to refer to.
. [Prototype] Type.getbasetype ()
Description
It actually returns the value of "typeof This.__basetype" and returns null if it is "undefined".
. [Prototype] Type.getinterfaces ()
Description
This allows you to get an array of interface objects implemented by the current instance, which is an array object.
. [Prototype] Type.getname ()
Description
Returns the name of the current object, including the namespace and class name, if "undefined" returns ".
. [Prototype] Type.implementsinterface (InterfaceType)
Description
Returns true if the current class has implemented all the definitions in the InterfaceType interface, or false. This can also be achieved in. NET inheritance excuses must implement the promise of all methods or attributes:
. [Prototype] Type.inheritsfrom (ParentType)
Description
Call this method to determine whether the current instance inherits from the ParentType class, such as: Var Isinherited=classa.inheritsfrom (CLASSB), and returns True if the current instance inherits from ParentType. otherwise returns false.
. [Prototype] Type.initializeBase (instance, basearguments)
Description
This is a fairly important function that initializes the constructor of the base function, or registers itself as a base function. Where instance is the object that initializes the base class, usually with this;basearguments as the parameter of the base function constructor, and can be null.
. [Prototype] Type.isimplementedby (typeinstance)
Description
This, in contrast to 6, is used to determine whether typeinstance implements all the definitions in the interface and returns false if the implementation returns TRUE.
. [Prototype] Type.isinstanceoftype (instance)
Description
Determines whether a class is a current instance of instance and is primarily used to determine whether a class is an instance of a class (subclass) that inherits from him. Return to True/false.
. [Prototype] Type.registerClass (TypeName, BaseType, Interfacetypes)
Description
This is a look to know is registered a class, BaseType and Interfacetypes are optional, while and. NET, basetype the most one, and the interface does not matter. This method is used to instantiate the constructor of the base function by Type.initializeBase in the first row, before initialization of a class is basetype.
. [Prototype] Type.registerInterface (TypeName)
Description
Registers a class as an interface, and the middle of the interface contains any handler functions.
. [Prototype] Type.resolveinheritance ()
Description
This is a fun way to copy the properties of the base class to extend the current class prototype, which is to extend the reflection in object-oriented programming.
. Type.getrootnamespaces ()
Description
static function (I don't know what other people call it, I'll call him static function is good:), this method can get all the namespaces array arrays (that is, return an array, including all namespaces).
. Type.isclass (Type)
. Type.isinterface (Type)
. Type.isnamespace (Type)
. Type.parse (Typename,ns)
Description
Awesome, you can create an object that uses Type.GetType ("Type,ns") in. NET, and invoke () to reflect the instantiation of a class. NS namespace Optional. If the class is not in a namespace (for example, type Class), TypeName can be null.
. Type.registerNamespace (NamespacePath)
Description
Registers a namespace.
. [Prototype] Type.registerenum (Name,flag)
Description
Registered as an enumeration type, flag determines whether it is a bit type, optional.
. Type.isenum (Type)
. Type.isflags (Type)
Written to write Hu, examples are not added, and the original understanding seems very vague, in order to make people more intuitive understanding, I put some examples here (HTML file):

If you want to test the enum to use the Space Reference script, provide examples of the script does not have the number class extension, so can not test enum, ah, a few hours passed, but also mastered a lot, in my writing this article is more and more vague , if there is anything wrong, please point out, allow Bill Gate to get Rich first, and then drive us rich, and finally realize the common prosperity of everyone:



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.