Js Study Notes (3)

Source: Internet
Author: User

An object-oriented language provides developers with four basic capabilities:
(1) Encapsulation-ability to store relevant information (regardless of data or methods) in objects.
(2) aggregation-the ability to store one object in another.
(3) Inheritance-the ability to obtain attributes and methods of a class from another class (or multiple classes.
(4) polymorphism-the ability to write functions or methods that can run in multiple ways.

Object Type

1. Local object
① Array class
② Date class
2. built-in objects
3. Host Object

Array class
The toString () and valueOf () Methods return special strings. This string is constructed by calling the toString () method for each item and then concatenating them with commas. For example, if you call the toString () method or valueOf () method for arrays with items "red", "green", and "blue", the return value is the string "red, green, blue ".
The only purpose of the join () method is to connect string values. The join () method has only one parameter, that is, the string used between array items.
The split () method converts a string to an array. The split () method has only one parameter, which is a string that is considered as a separator between array items. If you declare an empty string as a separator, each item in the array returned by the split () method is a character of the string.
The concat () method processes arrays in almost the same way as it processes strings. The parameter will be appended to the end of the Array, and the returned function value is the new Array object (including the items and new items in the original Array ).
The slice () method accepts one or two parameters, that is, the start position and end position of the item to be extracted. If there is only one parameter, this method returns all items starting from this position to the end of the array. If there are two parameters, this method returns all items between the first position and the second position, excluding the items at the second position.
Unshift () method, which places an item in the first position of the array, and then moves the remaining items downward.
The reverse () method reverses the order of array items.
The sort () method sorts the values of array items in ascending order. (Note: Only sort the string code, and sort the number array separately)
The most complex method of the splice () method is to insert data items into the middle of the array.
1. delete -- you only need to declare two parameters to delete any number of items from the array. These two parameters are the location of the first item to be deleted and the number of items to be deleted. For example, arr. splice () will delete the first two items in the array arr.
2. replace but not delete -- declare the three parameters to insert the data item to the specified position. These three parameters are the start position and 0 (number of array items to be deleted) and the items to be inserted. In addition, you can use the fourth, fifth, or more parameters to specify other items to be inserted. For example, arr. splice (2, 0, "red", "green") inserts "red" and "green" at location 2 ".
3. Replace and delete -- declare the three parameters to insert the data item to the specified position. These three parameters are the starting position, the number of array items to be deleted, and the items to be inserted. You can also specify more items to insert. The number of items to be inserted does not need to be equal to the number of items to be deleted. For example, arr. splice (, "red", "green") deletes the entry at location 2 in the array arr, and inserts "red" and "green" at location 2 ".
Concept of stack and queue
Difference 1
STACK: The last-in-first-out (LIFO) structure. Items Added first are deleted first. The insertion and deletion in the stack only occur at the top of the stack.

Queue: first-in-first-out (FIFO) structure, first-added items are deleted, element insertion only occurs at the end of the queue, and deletion takes place at the queue header.
Difference 2
STACK: "push to stack" is added to the top, and "pop up stack" is deleted from the top ".

Queue: "put" or "join" is added at the end of the team, and "get" or "out" is deleted at the head of the team ".
Application in Array class
STACK: the push () method is used to add one or more items at the end of the Array. The pop () method is used to delete the last Array item (length-1) and return it as the function value.

Queue: The push () method adds data items to the queue (that is, adding data items at the end of the array). The shift () method deletes the first item in the array and returns it as a function value.
Date class
The Date method (listed in the following table) is used to set or obtain a part of the Date value.

Method

Description

ToLocaleDateString ()

Display the time part of Date in location-specific format

GetTime ()

Returns the millisecond representation of the date.

SetTime (Milliseconds)

Sets the millisecond representation of a date.

GetFullYear ()

Returns the year of the date represented by four digits (for example, 2004, not just 04)

GetUTCFullYear ()

Returns the year of the UTC date represented by four digits.

SetFullYear (Year)

Set the year of the date. The parameter must be a four-digit year value.

SetUTCFullYear (Year)

Set the year of the UTC date. The parameter must be a four-digit year value.

GetMonth ()

Returns the month value of the date, represented by a number ranging from 0 (January 1, January) to 11 (January 1, December ).

GetUTCMonth ()

Returns the month value of the UTC date, represented by the number 0 (January) to 11 (December ).

SetMonth (Month)

Set the month of the date to a number greater than or equal to 0. For numbers greater than 11, the cumulative start years

SetUTCMonth (Month)

Set the month of the UTC date to a number greater than or equal to 0. For numbers greater than 11, the cumulative start years

GetDate ()

Returns the day of the month.

GetUTCDate ()

Returns the day of the month from the UTC date.

SetDate (Date)

Set the day of the month

SetUTCDate (Date)

Set the day of the month in UTC

GetDay ()

Returns the day of the week.

GetUTCDay ()

Returns the day of the week in UTC.

SetDay (Day)

Set the date to the day of the week

SetUTCDay (Day)

Set the UTC date to the day of the week

GetHours ()

Returns the hour value in the date.

GetUTCHours ()

Returns the hour value in UTC.

SetHours (Hours)

Set the hour value in the date

SetUTCHours (Hours)

Set the hour value in UTC date

GetMinutes ()

Returns the minute value of the date.

GetUTCMinutes ()

Returns the minute value in UTC.

SetMinutes (Minutes)

Set the minute value in the date

SetUTCMinutes (Minutes)

Set the minute value in UTC

GetSeconds ()

Returns the second value in the date.

GetUTCSeconds ()

Returns the second value in UTC.

SetSeconds (Seconds)

Set the second value in the date

SetUTCSeconds (Seconds)

Set the second value in UTC date

GetMilliseconds ()

Returns the millisecond value of the date. Note that this is not a millisecond value after January 1, January 1, 1970, but a millisecond value in the current time, for example, 4: 55: 34.20, where 20 is the millisecond value of the time.

GetUTCMilliseconds ()

Returns the millisecond value in UTC.

SetMilliseconds (Milliseconds)

Set the millisecond value in the date

SetUTCMilliseconds (Milliseconds)

Set the millisecond value in UTC date

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.