Object-oriented in JavaScript

Source: Internet
Author: User

1. What is object-oriented?

JS in everything is the object! The bottom of all objects is like a hash array.

In a program, an object is used to describe a specific thing in reality, so-called object-oriented is the instantiation of a class.

One thing in the real world contains properties and functions:

Attribute: A variable that describes a thing's characteristics, a value

Functions: Things can be done by the operation

What is an object: encapsulates storage space for multiple data and methods

What is a custom object: encapsulates the storage space for the properties and functions of a thing in reality.

The properties of something in reality become an attribute variable in the object.

The function of something in reality becomes a method (function) in the object

How to create an object:

1. Object Direct Amount       var obj={"Property name": value,        XXX: ...,               "method name":function() {...  This . Property name ...}               }
2. Use the New keyword       var obj=New// to Create an empty object      obj. property name = value;      Obj. method name =function() {... this. Property name ...}
3. Create * Same structure * with constructor * repeating *object: constructor: A special function that describes a class of object Structures 2 steps:1. Defining Constructorsfunctionsumname (value1,.....) {              This. property name =attribute parameter 1; //adds a property name to the object that is currently being created         //value assigned to attribute parameter 1             ...              This. Method name =function(){                  ... This. Property name ...} }      2To create an object with a constructor:varobj=NewSumname (value1,...);

2. What are the characteristics of object-oriented?

Object-oriented three main features: encapsulation inheritance polymorphism

Encapsulation: A property and method that describes the same thing, defined in an object

Inheritance: Properties and methods in the parent object that can be used directly by the child object

Polymorphic: The same object, which renders different states in different situations

Note: Overloads--the same method name, incoming parameters differ, perform different actions

Overriding: A child object feels that a member of the parent object is not good to use and can define itself to overwrite the members of the parent object

Object-oriented in JavaScript

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.