JavaScript Object-oriented one

Source: Internet
Author: User

From today on to write their own learning things, a little excited. (Just give mom massage foot, finger a bit bad to make) good, nonsense not to say, this is learning is JS object-oriented knowledge.

Object-oriented : is to use the idea of the object to write code, and we usually write JS is the process of writing. What is an object ? In fact, in the native JS there are many system objects, such as Date,array,json (object) and so on.

Object-oriented Programming (OOP) features: 1. Abstract: Seize the core question; 2. Encapsulation: Methods can only be accessed through objects; 3. Inheritance: A new object is inherited from an existing object; 4. Polymorphism: Different forms of multiple objects.

The composition of the object: Property + method. Next, create the first object.
function Aaa () {    this. Attribute   // property is written }varnew   function() {}// method is written

The above should be noted: 1. Capitalize the first letter. 2. Extract with the new keyword. 3. When using new to invoke a function AAA, this time the function is a pointer to the creation of this object A, and the return value of this function is the object A.

Constructor: Is the function Aaa () {...} above.

Prototype-prototype

Definition: Overriding an object method to allow the same method to exist in memory (improve performance).

Principle: The same properties and methods can be written to load on the prototype. For example: Array.prototype.sum = function () {}

Summarize the object-oriented notation: constructor ~ property; prototype ~ method.

JavaScript Object-oriented one

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.