Jscript Internal Objects

Source: Internet
Author: User
Tags date array contains numeric numeric value pow variable
js|jscript| objects

Internal objects
Microsoft Jscript provides 11 internal (or "built-in") objects. They are array, Boolean, Date, Function, Global, Math, Number, object, REGEXP, Error, and String objects. Each object has related methods and attributes, which are described in detail in the language reference. Some of the objects are also described in this section.

Array Object
An array subscript can be considered an object's property, which is referenced by a numeric index. Note named properties that are added to an array cannot be indexed by numbers; they are separated from the array elements.

Generate a new array using the new operator and the array () constructor, as shown in the following example.

var theMonths = new Array (12);
Themonths[0] = "the";
THEMONTHS[1] = "Feb";
THEMONTHS[2] = "Mar";
THEMONTHS[3] = "APR";
THEMONTHS[4] = "may";
THEMONTHS[5] = "June";
THEMONTHS[6] = "June";
THEMONTHS[7] = "Aug";
THEMONTHS[8] = "SEP";
THEMONTHS[9] = "OCT";
THEMONTHS[10] = "Nov";
THEMONTHS[11] = "DEC";
When an array is generated with the keyword array, Jscript contains the length property, which records the number of array entries. If no value is specified for the property, the set length is 0 and the array has no entry point. If you specify a numeric value, the length is set to that number. If more than one parameter is specified, the parameters are used as the entry point for the array. In addition, the number of parameters is assigned to the length property. The following example is equivalent to the previous example.

var theMonths = new Array ("", "Feb", "Mar", "APR", "may", "June",
"June", "Aug", "Sep", "Oct", "Nov", "Dec");
When you add an element to an array that is generated with a keyword array, Jscript automatically changes the value of the property length. Array indexes in Jscript always start with 0, not 1, so property length is usually 1 larger than the maximum index of an array.

String Object
In Jscript, strings (and numbers) can be treated as objects. The string object has built-in methods that you can use with your own string. One of these is the substring method, which returns a portion of the string. The method takes two digits as an argument.

astring = "0123456789";
var achunk = astring.substring (4, 7); Set the Achunk to "456".
var anotherchunk = astring.substring (7, 4); Set the Anotherchunk to "456".
Use the example above to generate an array:
Firstletter = themonths[5].substring (0,1); Set the variable firstletter to "J".
Another property of the String object is the length property. This property contains the number of characters in the string (the empty string is 0). It is a numeric value that can be used directly in calculations.

var howlong = "Hello world". Length//Set variable Howlong to 11.
Math Object
The Math object has many predefined properties and methods. The attribute is a special number. One of these special numbers is the PI value (approximately 3.14159 ...). )。 This is the Math.PI property, as shown in the following example.

Declare a RADIUS variable and assign a value.
var Circlearea = Math.PI * radius * RADIUS; Note Math and PI caps.
One of the built-in methods of the Math object is a power method (or POW) that uses this method to get the specified number of powers. The following example uses both PI and power.

This formula calculates the volume of a sphere with a given radius.
Volume = (4/3) * (Math.pi*math.pow (radius,3));
Date Object
The Date object can be used to represent any date and time, get the current system date, and calculate the interval of two dates. It has some predefined properties and methods. Typically, a Date object gives weeks, months, days and years, and times in hours, minutes, and seconds. This information is based on the number of milliseconds from the start of the January 1, 1970 00:00:00.000 GMT, where GMT is Greenwich Mean Time (the preferred term is UTC, or "global Standard Time", which refers to a signal that is published by the "World Time Standard"). Jscript can handle dates in the range of 250,000 B.C to 255,000 A.D.

Creates a new Date object using the new operator. The following example calculates the number of days that have elapsed in the year and the number of days remaining this year.

/*
This example uses an array of the month names defined earlier.
The first statement is in the "Day Month Date 00:00:00 Year" format
Assign a value to a thisistoday variable.
*/
var thisistoday = new Date ();

var today = new Date (); Get today's date.

Extract year, month, day.
var thisyear = Today.getfullyear ();
var thismonth = Themonths[today.getmonth ()];
var thisday = Thismonth + "" + today.getdate () + "," + thisyear;
Number Object
In addition to the special numeric attributes (such as PI) available in the Math object, the number object has several other numeric properties in Microsoft Jscript.

Attribute description
The maximum possible number of max_value is approximately 1.79E+308, which can be positive or negative. (The specific values vary slightly from system to network.) )
The minimum possible number of min_value is approximately 2.22E-308, which can be positive or negative. (The specific values vary slightly from system to network.) )
NaN Special non-quantitative value, "not numeric".
Positive_infinity any positive values larger than the maximum positive number (Number.MAX_VALUE) are automatically converted to this value, representing positive infinity.
Negative_infinity any value that is smaller than the smallest negative number (negative Number.MAX_VALUE) is automatically converted to this value, representing negative infinity.

Number.NaN is a special attribute that is defined as "not numeric." For example by 0 to return NaN. An attempt to parse a string that cannot be resolved to a number also returns Number.NaN. The result of comparing NaN with any numerical value or itself is unequal. You cannot test NaN results by comparing it to Number.NaN, but you should use the isNaN () function.



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.