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 for strings Code To sort the number array)
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

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.