JS built-in objects

Source: Internet
Author: User
Tags italic font mathematical constants mathematical functions natural logarithm time and date time in milliseconds

Mark related points of knowledge:
First, what is JS's built-in object, and what does it include? (The following information is transferred from the integration of online resources)
(W3shool JS manual address: http://www.jb51.net/w3school/js/js_reference.htm)
As a programming language, JavaScript provides a number of built-in objects and functions. Built-in objects provide several of the most common features of programming. There are several types of JavaScript built-in objects.
String object: Handles all string operations
Math object: Handling all mathematical operations
Date object: Handling the storage, conversion, and expression of dates and times
Array object: Provides a model of an array, storing large amounts of ordered data
Event object: Provides various processing information for JavaScript events
Built-in objects have their own methods and properties and are accessed in the following ways:
Object name. Property name
Object name. Method name (parameter table)

1. Time Objects

A time object is a built-in object of JavaScript that must be declared before it can be used.
Basic syntax
var curr=new Data ();
Note the use of the keyword new here, the first letter of Data () must be capitalized.
Grammatical explanations
Use new to declare a new object entity. The syntax for using the new operator is as follows:
Instance object name =new object name (parameter list)
The Date object provides the following 3 classes of methods:
Get the current time and date from the system
Set the current date and time
Complete the conversion between time and date with a string
The following table describes the most common ways to get the time and date of a system

methods for processing time and dates in a Date object

type of method Method Name function Description
Get Time or date GetDate Get the current date
Get Time or date GetDay Get the current day
Get Time or date GetHours Get the current hour
Get Time or date Getminutes Get the current minute
Get Time or date GetMonth Get the current month
Get Time or date Getseconds Get the current seconds
Get Time or date GetTime Gets the current time (in milliseconds)
Get Time or date getTimezoneOffset Get the current time zone offset information
Get Time or date GetYear Get the current year
Practice NOTES:
<!--note the difference between getdate and getday, GETDATE returns the date (1-31), and Getday returns the day of the week ()--
<!--also note that create arrays remember to use the new keyword, for example: Var myarray=new array ()--
<!--also learn two ways to assign values to arrays:
1. The first method can create any number of values, just like creating any number of variables:
Such as:
var mytechnic=new Array ()
mytechnic[0]= "HTML"
mytechnic[1]= "CSS"
mytechnic[2]= "JS"
You can also use an "integer argument" to control the capacity of an array.
2. The second method:
var mycars=new Array ("Saab", "Volvo", "BMW")

If you want to modify the values in the array, assign the new value directly: mytechnic[2] = "jquery"
-

2. Mathematical objects (more abstract)

The built-in math object can be used to handle a variety of mathematical operations. It defines some commonly used mathematical constants, such as Pi pi=3.1415926. Various operations are defined as built-in methods of the Math object, and can take advantage of the methods that are called directly.
Basic syntax
Math. Mathematical functions (parameters)
Or
With (Math)
{
Mathematical functions
}
Grammatical explanations
The WITH statement provides a simple and clear way to express the relationship between its properties and methods. To put it simply, within the scope of the with and statement, any property or method that does not indicate the object is the default object, which is given at the beginning of the WITH statement. The syntax for using the WITH statement is as follows:
With (object name)
{
Statement block ...
}

3. String objects

You typically use a function provided by a string object to handle a string. string handling of strings mainly provides the following methods.
CharAt (IDX): Returns the character at the specified position
IndexOf (CHR): Returns the position of the specified substring, from left to right. No return-1 found.
LastIndexOf (CHR): Returns the position of the specified substring, from right to left. No return-1 found.
toLowerCase (): Converts all characters in a string to lowercase.
toUpperCase (): Converts all characters in a string to uppercase.

4. Array objects (this one is especially focused tonight-the array Object!) )

Basically all programming languages provide array objects, which organize the same kind of data together, which is very convenient and efficient to access. such as the Java and C languages. As with the C language, the subscript of an array begins with a clump of zeros. Once an array is created, you can use the [] symbol to access an array of individual elements.

The following is a summary of some manual types (for JS built-in objects):

1.Date
Properties (1):
constructor function reference for objects created by
Prototype properties and methods that can be added to an object
Method (43):
GetDay () returns the day ordinal of a week (0-6)
GetYear () returns the year. Before 2000 for 2 bits, 2000 (inclusive) after 4 bit
getFullYear () returns the full number of 4-bit years
GetMonth () Number of months returned (0-11)
GetDate () return Day (1-31)
GetHours () return hours (0-23)
Getminutes () return minutes (0-59)
Getseconds () returns the number of seconds (0-59)
Getmilliseconds () returns milliseconds (0-999)
GetUTCDay () based on international time to get now is the day of the Week (0-6)
getUTCFullYear () to obtain a complete year based on international time
getUTCMonth () According to the international time to get the month (0-11)
getUTCDate () According to the international time to get the day (1-31)
getUTCHours () According to international time to get the hour (0-23)
getUTCMinutes () Returns minutes according to international time (0-59)
getUTCSeconds () Returns seconds according to international time (0-59)
getUTCMilliseconds () returns milliseconds based on international time (0-999)
GetTime () returns the number of milliseconds that are spent since January 1, 1970 0:0:0
getTimezoneOffset () Returns the time zone bias value, which is the number of minutes between Greenwich Mean Time (GMT) and the time zone setting of the computer where the script is running.
Parse (datestring) returns the number of milliseconds since January 1, 1970 00:00:00 in the date string
Setyear (yearint) sets the year. 2-digit or 4-digit number
setFullYear (yearint) sets the year. 4 digits
Setmonth (Monthint) Set month (0-11)
SetDate (Dateint) Set Day (1-31)
Sethours (Hourint) Set hours (0-23)
Setminutes (MININT) set number of minutes (0-59)
Setseconds (Secint) Set number of seconds (0-59)
Setmilliseconds (Milliint) Set MS (0-999)
setUTCFullYear (Yearint) set the year according to the international time
setUTCMonth (Monthint) set the month according to International Time (0-11)
SetUTCDate (Dateint) set the day according to the International Time (1-31)
setUTCHours (hourint) Set hours according to international time
setUTCMinutes (MININT) Set minutes according to international time
setUTCSeconds (Secint) set the seconds according to the international time
setUTCMilliseconds (Milliint) to set milliseconds based on international time
SetTime (Timeint) sets the time since January 1, 1970. Number of milliseconds
toGMTString () Converts the Date object (a numeric value) to a GMT time string, such as: weds,15 June l997 14:02:02 GMT.
toUTCString () converts dates of a Date object to a string based on Universal Time
toLocaleString () Turns the Date object's dates (a numeric value) into a string, using the specific date format used on the computer on which it is configured
Tosource () Displays the source code of the object
ToString () Converts a Date object to a string
UTC (yyyy, MM, DD, hh, MM, SS, msec) returns the gap from Greenwich Mean time to a specified time in milliseconds
ValueOf () returns the original value of the Date object
2.Math
Property:
constructor function reference for objects created by
Prototype properties and methods that can be added to an object
E Euler constant, base of natural logarithm (approximately equal to 2.718)
Natural logarithm of LN2 2 (approximately equal to 0.693)
Natural logarithm of LN10 10 (approximately equal to 2.302)
LOG2E the logarithm of E with a base of 2. (approximately equal to 1.442)
log10e logarithm of E with a base of 10 (approximately equal to 0.434)
Pi∏ value (approximately equal to 3.14159)
The square root of the sqrt1_2 1/2 (0.5) (that is, the square root of the L divided by 2, approximately equal to o.707)
SQRT2 2 square root (approximately equal to 1.414)
Method:
ABS (x) returns the absolute value of a number
ACOs (x) returns the inverse cosine value of a number
ASIN (x) returns the inverse chord value of a number
Atan (x) returns the inverse tangent value at-PI/2 and PI/2
ATAN2 (y,x) returns (x, y) at the angle between-pi and PI
Ceil (x) returns the largest integer after X rounding
COS (x) returns the cosine of a number
EXP (x) returns E^X value
Floor (x) returns the smallest integer after rounding x
Log (x) returns the natural logarithm of base E
Max (x, y) returns the larger number between x and Y
Min (x, y) returns the smaller number between x and Y
Pow (x, y) returns the value of Y^x
Random () returns a stochastic function between 0 and 1
Round (x) rounding out and rounding
Sin (x) returns the sinusoidal value of a number
SQRT (x) returns the square root of a number
Tan (x) returns the tangent of an angle
Tosource () Displays the source code of the object
ValueOf () returns the original value of a mathematical object
3.Number
Property:
Max_value the largest possible VALUE a number in JavaScript can has 1.7976931348623157E+308
Min_value the smallest possible VALUE a number in JavaScript can has 5E-324
NaN Equal to a value, that's not a number.
Negative_infinity A value that's less than min_value.
Posotive_infinity A value is greater than max_value.
Prototype A static property of the Number object
Method:
ToString Returns A string representing the specified object
ValueOf () returns the original value of a mathematical object
4.Boolean
Property:
constructor function reference for objects created by
Prototype properties and methods that can be added to an object
Method:
Tosource () Displays the source code of the object
ToString () converts the Boolean value to a string and returns the result
ValueOf () returns the original value of the Boolean object
5.String
Property:
constructor function reference for objects created by
Prototype properties and methods that can be added to an object
Length returns the character lengths of the string
Method (20):
Anchor ("name") is used to convert a string into an HTML anchor mark (<a name=>).
Big () turns the text in the string into a large font (<BIG>)
Blink () turns text in a string into a blinking font (<BLINK>)
Bold () turns the text in the string into a black font (<B>)
Fixed () turns the text in a string into a regular-spaced font, the Telegraph form (<TT>)
FontColor (color) sets the colors of the text in the string (<font color=>)
Fontsize (size) To change the text in a string to a specified size (<FONTSIZE=>)
Italics () turns text in a string into italic font (<I>)
Link (URL) used to convert a string into a-html link tag (<a href=>)
Small () turns the text in a string into a small font (<SMALL>)
Strike () turns the text in the string into a crossed-out font (<STRIKE>)
Sub () turns the text in the string into a subscript (subscript) font ((sub>)
SUP () turns text in a string into superscript (superscript) font (<SUP>)
CharAt (index) returns the character at the specified index
charCodeAt (index) returns an integer that represents the Unicode encoding of the character at the specified position in a string object
Concat (string2) connecting two or more strings
fromCharCode (NUM1, num2, ..., numn) gets the specified Unicode value and returns the string
IndexOf (searchstring, StartIndex) returns the position of the first occurrence of the specified string in a string
Lastlndexof (searchstring, StartIndex) returns the position of the last occurrence of the specified string in the string
Match (Regex) finds the specified value in a string
Replace (regex, newstring) replaces some characters in a string with other characters
Search (Regex) finds strings for an execution value
Slice (StartIndex, endIndex) extracts some characters and returns the remainder in a new string
Split (delimiter) assigns a string to an array
substr (startIndex, length) from StartIndex, take length of characters
SUBSTRING (StartIndex, endIndex) characters from StartIndex and EndIndex, excluding EndIndex
toLowerCase () turns text in a string into lowercase
toUpperCase () turns the text in the string into uppercase
Tosource () Displays the source code of the object
ValueOf () returns the original value of the string object
6.Array
Property:
constructor function reference for objects created by
Prototype properties and methods that can be added to an object
Index for an array created by a regular expression match, the zero-based index of the match in the string.
Input for an array created by a regular expression match, reflects the original string against which the regular Expressio N was matched.
Length gets the number of array elements, that is, the maximum subscript plus 1
Method (13):
Concat (Array1,arrayn) joins two or more than two array values and returns the result after merging
Join (String) merges elements of the array into strings, string as delimiters. If omitted, it is merged directly, no longer separated
Pop () moves the last element in the array and returns the element
Push (value) adds one or more elements to the end of the array and returns a new array length value
Reverse () Reverses the order of the elements in the array, and reverses the arrangement
Shift () moves the first element in an array and returns the element
Slice (start, deletecount, [item1[, item2[,... [, Itemn]]]) Removes one or more elements from an array and, if necessary, inserts a new element at the location of the removed element, returning the element that was removed
Sort (compare Function), in the case of no sort number, is arranged alphabetically by element, and if it is not a string type, it is converted to a string and then sorted, returning the sorted array
Splice () to delete and add new elements to an array
Tosource () Displays the source code of the object
ToString () returns a string of all elements of the array, separated by commas
Unshift (value) adds one or more elements to the beginning of an array, and returns the new length
ValueOf () returns the original value of the array object
7.RegExp
Property:
$ $, ..., $9 parenthesized substring matches, if any.
$_ See input.
$* See Multiline.
$& See lastmatch.
$+ See Lastparen.
$ ' See leftcontext.
$ ' See rightcontext.
Global Whether or not to test the regular expression against all possible matches in a string, or only against the first.
IgnoreCase Whether or not to ignore case while attempting a match in a string.
The input the string against which a regular expression is matched.
LastIndex the index at which to start the next match.
Lastmatch the last matched characters.
Lastparen the last parenthesized substring match, if any.
Leftcontext the substring preceding the most recent match.
Multiline Whether or not to search in strings across multiple lines.
Rightcontext the substring following the most recent match.
SOURCE the text of the pattern.
Method:
Compile compiles a regular expression object.
EXEC executes a search for a match in its string parameter.
Test Tests for a match in its string parameter
8.Function
Property:
Arguments an array corresponding to the arguments passed to a function.
Arity indicates the number of arguments expected by the function.
caller specifies which function called the current function.
Prototype allows the addition of properties to a Function object.
Method:
ToString Returns A string representing the specified object.
9.Object
Property:
constructor specifies the function that is creates an object ' s prototype.
Prototype allows the addition of properties to all objects.
Method:
Eval evaluates a string of JavaScript code in the context of the specified object.
ToString Returns A string representing the specified object.
Unwatch removes a watchpoint from a property source the object.
ValueOf Returns The primitive value of the specified object.
Watch Adds a watchpoint to a property source the object.
10. Global
Property:
Infinity A value that specifies a positive or negative infinity
NaN specifies a "non-numeric" value
Undefined specifies a variable that is not assigned a value
Method:
decodeURI () decodes an encrypted URI
decodeURIComponent () Decodes the encrypted URI component
encodeURI () encrypts a string as a URI
encodeURIComponent () encrypts a string as a URI component
Escape (String) encrypts a string
Unescape () decodes a string using escape ()
Eval (string) to judge a string and execute it as script code
Isfinite (number) detects whether a value is a finite digit, returns TRUE or False
IsNaN (String) detects whether a value is not a finite number
Number () Converts the value of an object to a digit
parsefloat (String) resolves a string to a floating-point number
parseint (String) resolves a string to an integer, not a rounding operation, but a tangent end
String (object) converts an object value to a string
Number (object)
11. Events
Property:
A. Window events that are only valid in the body and frameset elements
When the onload page or picture loading is complete
OnUnload when the user leaves the page
B. Form element events that are valid in form elements
OnChange when the contents of the box change
onsubmit When you click the Submit button
OnReset when the mouse button is re-clicked
Onselect Text is selected
When the onblur element loses focus
onfocus when an element gets focus
C. keyboard events, which are not valid in the Base,bdo,br,frame,frameset,head,html,iframe,meta,param,script,style,title element
onkeydown When you press the keyboard key
onkeypress Press or hold the keyboard key
onkeyup When the keyboard button is released
D. Not valid in the Base,bdo,br,frame,frameset,head,html,iframe,meta,param,script,style,title element
When an onclick mouse clicks on an object
OnDblClick when the mouse double-clicks an object
OnMouseDown when the mouse is pressed
OnMouseMove when the mouse is moved
onmouseout when the mouse leaves the element
onmouseover when the mouse passes through an element
OnMouseUp When the mouse button is released
E. Other
onresize when a window or frame is redefined
Onabort when a picture download is interrupted
OnError When an error occurs when loading a document or picture
Custom objects: There are two ways to initialize objects and define constructors
A: Initialize the object
For example: Object ={attribute 1: value 1; Property 2: Value 2; .... Attribute N: Value n} Note: Each attribute/value pair is separated by semicolons;
B: The object that defines the constructor
For example:
Function name (property 1, Property 2,...... Attribute N) {
this. Property 1 = property value 1;
this. Property 2 = property value 2;
This. Attribute N= property value N;
This. Method Name 1 = function Name 1;
This. Method Name 2 = function Name 2;

JS built-in objects

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.