Home  >  Article  >  Web Front-end  >  JavaScript Tutorial: Use of Object Methods and Properties

JavaScript Tutorial: Use of Object Methods and Properties

黄舟
黄舟Original
2016-12-22 15:42:031312browse

JavaScript provides us with some very useful common internal objects and methods. Users do not need to use scripts to implement these functions. This is the true purpose of object-based programming.

JavaScript provides three objects: string (string), math (numeric calculation) and Date (date) and some other related methods. This provides very favorable conditions for programmers to quickly develop powerful script programs.

1. Commonly used internal objects

In JavaScript, there are two situations for referencing object properties and methods: One is that the object is a static object, that is, there is no need to create a property or method for it when referencing it. Instance; while another object must create an instance for it when referencing its object or method, that is, the object is a dynamic object.

References to JavaScript internal objects are centered around its properties and methods. Therefore, clarifying the static nature of objects is of great significance for mastering and understanding JavaScript internal objects.

a. String object

1. Attributes of string object

This object has only one attribute, length. It indicates the number of characters in the string, including all symbols.

Example:

mytest="This is a JavaScript"

mystringlength=mytest.length

Finally mystringlength returns the length of mytest string as 20.

2. Methods of String Objects

There are 19 methods in tring objects. Mainly used for display of strings in Web pages, font size, font color, character search and character case conversion.

b. Math object of arithmetic function

Function: Provide some self-described operations except addition, subtraction, multiplication and division. Such as logarithms, square roots, etc.


2. System functions in JavaScript

System functions in JavaScript are also called internal methods. It provides system functions that are independent of any object. Using these functions does not require the creation of any instances and can be used directly.

1. Return the value in the string expression:

Method name: eval (string expression), example:

test=eval("8+9+5/2");

2. Return the string ASCI code :

Method name: unEscape (string)

3. Return character encoding:

Method name: escape(character)

4. Return real numbers:

parseFloat(floutstring);

5. Return numbers in different bases:

parseInt(numbestring,rad. Please pay attention to the PHP Chinese website (www.php.cn) for content!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn