javascript-Reference type--object type

Source: Internet
Author: User

A reference type is a data structure that is essentially a collection of information and functions. Reference types are also sometimes referred to as object definitions because they describe the properties and methods that a class of objects have. The reference type is equivalent to the class in Java, although JavaScript is an object-oriented language, but it does not support the traditional object-oriented language classes and interfaces.

An object is an instance of a particular reference type that can be created by using the new operator followed by the name of the object type to be created. For example:

var o = new Object ();

This line of code creates a new instance of the object reference type, and then saves the instance in the variable O. It only defines the default properties and methods for new objects, and it is not useful to create an instance of object, but to understand an important thought: the values of most reference types in JavaScript are instances of type object.

There are two ways to create an object instance, one using the new operator followed by the object constructor, for example:

var person = new Object ();p erson.name = "Tom";p erson.age = 21;

Another way is to use object literals to create, for example:

var person = {   Name: "Tom",   age:21  };

When created with object literals, property names can also be in string form, for example:

var person = {   ' name ': ' Tom ',   ' age ': +  };

Object literals can also be used for function arguments, for example:

function Showinfo (args) {    alert ("Name:" + Args.name + ", Age:" + args.age);} Showinfo ({
Name: "Tom",
Age:21
}); Name: Tom, Age: 21

In JavaScript, you can access object properties in the form of a point, and you can access the properties of the object in square brackets, using the form of square brackets to enclose the property name as a string in square brackets, for example:

var person = {   Name: "Tom",   age:21  };alert (person.name);       Tom     alert (person["name"]);  Tom  

Each instance of object has the following properties and methods:

Constructor: Holds the function that is used to create the current object.

hasOwnProperty (PropertyName): Used to check whether a given property exists in the current object instance, and the argument must be in the form of a string.

isPrototypeOf (object): Used to check whether an incoming object is a prototype of the current object.

propertyIsEnumerable (PropertyName): Used to check whether the given property can be enumerated using for-in, the argument must be in the form of a string.

toLocaleString (): Returns the string representation of the object that corresponds to the region where the execution environment is executed.

ToString (): Returns the string representation of the object.

ValueOf (): Returns the string, numeric, or Boolean representation of an object.

PS: This content is summarized based on JavaScript elevation knowledge and is used for personal note sharing.

javascript-Reference type--object type

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.