Properties and methods for JavaScript common objects

Source: Internet
Author: User
Tags natural logarithm square root

Properties and methods of common JavaScript effects objects

Demo: http://www.huiyi8.com/jiaoben/

[Code] properties and methods for common objects

JavaScript provides us with some of the most useful internal objects and methods. Users do not need to use scripts to implement these functions. This is the real purpose of object-based programming.
The JavaScript provides string (string), math (numeric), and date (date) Three objects and some other related methods. This provides very favourable conditions for programmers to quickly develop powerful scripting programs.

1. Common internal objects
In JavaScript, there are two cases of reference to object properties and methods: One is that the object is a static object, that is, you do not need to create an instance of it when referencing the property or method of the object, and the other object or method that references it must create an instance of it, that is, the object is a dynamic object.
A reference to a JavaScript internal object that is tightly centered around its properties and methods. Therefore, it is very important to understand the object's static nature to grasp and comprehend the internal object of JavaScript.

1), String object
O String object: internal static.
o When accessing properties and methods, the (.) operator can be used.
o Basic use Format: Objectname.prop/methods
(1) Properties of a String object
The object has only one property, which is length. It indicates the number of characters in the string, including all symbols.
Cases:
Mytest= "This is a JavaScript"
Mystringlength=mytest.length
The last Mystringlength returns the length of the mytest string as 20.
(2) Methods of String objects
There are 19 methods for a string object. It is used primarily for the display of strings in Web pages, font size, font color, search for characters, and case conversion of characters.
The main methods are as follows:
O Anchor Point anchor (): This method creates the same anchor tag as in an HTML document. Use anchor as in HTML (A name= ""). Accessed through the following format: String.anchor (anchorname).
O Control methods for character display
Big font display, italics () italic display, Bold () bold character display, blink () character flashing display, small () character display in small font, fixed () fix highlighted word display, fontsize (size) control font size, etc.
o font color method; fontcolor (color)
o String Case Conversion
toLowerCase ()-Lowercase conversion, touppercase () uppercase conversion. The following converts a given string into uppercase and lowercase formats, respectively:
String=stringvalue.touppercase and String=stringvalue.tolowercase.
o character search: Indexof[charactor,fromindex]
Searches for the first occurrence of the charactor from the specified FORMINDTX location.
Returns a partial string of strings: substring (start,end)
All characters from start to end are returned.
 
2) Math object for arithmetic functions
Function: Provide some readme operation except addition, subtraction, multiplication and addition. such as logarithm, square root and so on.
Statics: Static objects
(1) Main attributes
Math provides 6 properties, which are the constant e used in mathematics, the natural logarithm of 10 as the base, the natural logarithm LN2 of 2, the 3.14159 Pi, and the square root of the square root of the LN10 sqrt1-2,2 for SQRT2.
(2) Main methods
Absolute value: ABS ()
Sine cosine: sin (), cos ()
Inverse sine cosine: asin (), ACOs ()
Tangential tangent: tan (), Atan ()
Rounding: Round ()
Square root: sqrt ()
Values based on several parties: Pow (base,exponent)
...
3), Date and Time objects
Function: Provides an object about the date and time.
Static: Dynamic, that is, you must create an instance with the new operator. Cases:
Mydate=new Date ()
The Date object does not provide direct access to the property. Only has the method to get and set the date and time.
Date Start value: January 1, 1770 00:00:00.
1. Time method for getting a date
GetYear (): Number of years returned
GetMonth (): Return month
GetDate (): Returns the date of the day
GetDay (): Return day of the week
GetHours (): Returns the number of hours
Getmintes (: Returns the number of minutes
Getseconds (): Returns the number of seconds
GetTime (): Returns the number of milliseconds
(2) Set the date and time:
Setyear (); Set year
SetDate (): Set month
Setmonth (): Sets the number of copies in the month
Sethours (): Set Number of hours
Setmintes (): Set the number of minutes
Setseconds (): Sets the number of seconds
SetTime (): Set the number of milliseconds
...
2. System functions in JavaScript
The system functions in JavaScript are also called internal methods. It provides system functions that are independent of any object, and use these functions without creating any instances that can be used directly.
1. Returns the value in a string expression:
Method Name: eval (string expression), for example:
Test=eval ("8+9+5/2");
2. Return string ASCI code:
Method Name: Unescape (String)
3. Returns the encoding of the character:
Method Name: Escape (character)
4. return real numbers:
Parsefloat (floustring);
5. Returns the number of different binaries:
parseint (Numbestring, Rad. X
Where Radix is the number of the binary, numbs string number

Properties and methods for JavaScript common objects

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.