[ASP. NET Ajax] ECMAScript basic class and Asp.net Ajax Class & amp; lt; Obje

Source: Internet
Author: User

"Everything is Object", which is known to anyone in the object-oriented programming language. But for me, this is a feeling that it is hard to say. Due to my lack of JavaScript and knowledge, I learned how to use ECMAScript while reading the Asp.net Ajax class library. In. all classes in NET are inherited from objects. Similarly, in JS, all classes inherit from objects. Therefore, if the Object is extended, then all the descendants that inherit the Object class will surely have the kinship of the ancestor.

Now that you are learning JavaScript, let's mention its original data type here. In JavaScript, there are five original data types (Undefined, Null, Boolean, Number, String ), you can use typeof to determine the Data Type of variables and values.

1. Undefined: When a variable is declared but not initialized, or the function does not explicitly return a value, the variable or function is of the Undefined type and is a feature of the Null type.

2. Null: if the value of an object does not exist, null is returned for the object.

3. Boolean: it can be seen that 0 is not equal to false, but can be converted to false.

4. Number: 32-bit integer data or 64-bit floating point data can be defined. According to some information on the Internet, floating point numbers are stored in the String type before they are computed (I do not know whether it is true or false ). When the floating point data is large or small (six digits can be moved before and after), the E representation is used to represent the floating point data, and up to 17 bytes of data can be stored. In addition, the isFinite () method can determine whether a numerical value is limited. The isNaN () method can determine whether a data type is non-numeric. You can use parseInt () and parseFloat () to convert other types to numeric types. If the conversion fails, NaN (Not a Number) is returned ).

5. string: This is a unique primitive type with no size restrictions. Other types can be converted to the String type through toString, it is worth mentioning that you can add 2.8.16 as the output binary, octal, and hexadecimal strings to convert numbers to the String type.

Next, let's take a look at the Object type. An Object can be declared through var obj = new Object. Like objects in. NET, it is the base class of all classes.

It has two attributes: constructor (equivalent to the constructor in. NET). We recommend that you reference an Object function. For an Object class, this reference points to the local Object () method. A reference value of the Prototype object in the prototype object. This attribute reflects the extended attributes and methods of prototype in each object, and also uses this attribute class extension and reflection class in Asp.net Ajax.

HasOwnProperty (property)-determines whether the property exists in the object. The property data type is string; isPrototypeOf (object)-determines whether an object is prototype of another object; propertyIsEnumerable (property) -Determine whether the given attributes can be listed using the for statement; toString ()-returns the original type of the object string; valueOf ()-returns the appropriate original value of the object, for most classes, the returned value is the same as that of toString. These are the methods of the original Object. In other classes, these methods are also inherited.

In Asp. NET Ajax, Microsoft has added two methods to the original Object to expand the entire class library to be more suitable for. NET developers:

Object. _ typeName = "Object ";

Object. getType = function (B ){

Var a = B. constructor;

If (! A | typeof! = "Function" |! A. _ typeName | a. _ typeName = "Object") return Object;

Return

};

Object. getTypeName = function (){

Return Object. getType (a). getName ()

};

From the above we can see that Object. the static method getType (type) can obtain the Object of a class, while the Object. getTypeName (type): Call [prototype] Type. getName () and get the class name (including namespace ). There is nothing to say. Let's take a look at the test below:

<Asp: ScriptManager ID = "ScriptManager1" runat = "server"/>

<Div>

<Script language = "javascript">

Type. registerNamespace ("NExplus ");

// Define a class;

NExplus. ObjectTest = function (name ){

This. _ name = name;

}

NExplus. ObjectTest. prototype. getName = function (){

Return (this. _ name = undefined )? Null: this. _ name;

}

NExplus. ObjectTest. prototype. setName = function (name ){

This. _ name = name;

}

// Register class;

NExplus. ObjectTest. registerClass ("NExplus. ObjectTest ");



NExplus. TestObject = function (){

Var a = new NExplus. ObjectTest ("Test is success? ");

Document. write (a. getName ());

Document. write ("<br/> ");

A. setName ("Success! ");

Document. write (a. getName ());

Document. write ("<br/> ");

Document. write (Object. getTypeName (a) + "<br/> ")

}

// Run;

NExplus. TestObject ();

</Script>

</Div>

Running result:

Test is success?
Success!
NExplus. ObjectTest

This is relatively simple. Microsoft only wants. NET Framework is closer to the extended Object class. I think these two classes should be rarely used in the development process. The above test will test attribute J by the way. I 'd like to know if there is any kind of good-hearted person who has translated the ECMAScript standard document and read the English. <. by the way, a bundle of my two operators is attached: |: starting from the first one, a meaningful return is returned; otherwise, the last expression (not necessarily a Boolean value) is returned );&&: starting from the first one, it returns meaningless (0, null, undefined, "", false, NaN); otherwise, it returns the last expression (not necessarily a Boolean value ).

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.