JavaScript learning Summary (2) array and object Section

Source: Internet
Author: User
An Object is an unordered set that stores any type of objects. All other objects inherit from this Object. There are two types of Object creation: the new operator and the literal representation.

Object Section

Object Type

An Object is an unordered set that stores any type of objects. All other objects inherit from this Object.
There are two types of Object creation: the new operator and the literal representation.

1. Use the new operator to create an Object

Var obj = new Object (); // note the upper case, you can also directly write the Object ()

Note: The new Object is generated using the new Object () method, which is equivalent to the literal method obj =.

2. Create using the literal method:

Var obj = {name: 'trigger4', age: 21}; // it is best to add a semicolon

When an Object is declared using a literal, the Object () constructor (except FF) is not called)

Object. prototype Object

All constructors have a prototype attribute pointing to a prototype object.

Object.prototype.print = function(){ console.log(this)};var obj = new Object();obj.print() // Object

The instance obj directly inherits the attributes and methods of Object. prototype.

1. The object is only a special type of data. The object has attributes and methods. JavaScript is an object-oriented language, but JavaScript does not use classes. JavaScript is based on [prototype] [1] instead of class-based. 2. attribute: a variable that belongs to a specific object. Method: it is a function that can only be called by a specific object. 3. js objects are a collection of attributes and methods. A method is a function that is a member of an object. An attribute is a value or a group of values (in the form of an array or object) and a member of an object. 4. js objects are based on constructors. When using constructors to create a new object, it can be said that a new object is instantiated. Attribute is the variable inside the constructor function.

Objects instantiated using constructors:

cat = new Animal();

Javascript is an object-based language. Almost everything you encounter is an object. However, it is not a real Object-Oriented Programming (OOP) language, because its syntax does not contain class ).

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.