An analysis of object types object_ basic knowledge in JavaScript

Source: Internet
Author: User

An object in ECMAScript is actually a collection of data and functionality.
Object in ECMAScript is the basis of all objects.
Understanding: Object type is the basis for all instances of it, in other words, any properties and methods that the object type has also exist in more specific objects.
An instance of object has the following properties and methods
1.Constructor: Save the function used to create the current object
2.hasOwnProperty (PropertyName): Checks whether a given property exists in the current object instance (not in the prototype). Where the property name as a parameter must be specified as a string
3.isPrototypeOf (object): Used to check if an incoming object is a prototype of another object
4.toLocalString (): Returns a string representation of an object that corresponds to the execution environment
5.toString (): Returns the string representation of an object
6.valueOf (): Returns a string, numeric, or Boolean representation of an object. Usually the same as the return value of the ToString () method

Global objects
Global objects have important uses in JavaScript: Global object properties are globally defined symbols, JavaScript programs can be used directly, and when the interpreter starts, it creates a new global object and gives it a set of initial properties defined:
Global properties, such as Undefined, Infinity
Global functions, such as parseint ()
constructor, such as data (),
Global objects, such as math and JSON

Wrapping Objects
look at an example of this:

var s = "Hello world!";
var word = s.substring (S.indexof ("") +1, s.length);

Since the string is not an object, why does it have attributes? JavaScript converts a string value to an object by calling the new string (s) as long as the property of the string s is referenced.
As with strings, numbers and Boolean values also have corresponding methods. Other similar packaging classes:

Number Object
String object
Boolean Object
Function Object
RegExp object
Error
syntaxerror
Referenceerror
TypeError ...


Immutable original values and mutable original object references
The original value is immutable, the comparison of the original value is the value comparison, and the object comparison is not a value comparison: Even if two objects contain the same attributes and the same values, they are not equal. We usually refer to an object as a reference type, the value of an object is a reference, and the comparison of objects is a reference comparison, and they are equal only if they refer to the same base alone;

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.