Home > Web Front-end > JS Tutorial > JavaScript Intermediate Notes Chapter 5 The Basics of Object Orientation_Javascript Skills

JavaScript Intermediate Notes Chapter 5 The Basics of Object Orientation_Javascript Skills

WBOY
Release: 2016-05-16 18:46:30
Original
903 people have browsed it
1. The basis of object-oriented
Objects are the basis of JavaScript. At the most basic level, an object is a collection of properties.
1, Creation of objects

[Ctrl A Select all Note: If you need to introduce external Js, you need to refresh to execute
]

I believe many friends are interested in these creations I have been exposed to the object's method many times, and I am very familiar with it. 2. Use of objects

Unlike other object-oriented languages, JavaScript does not have the concept of classes. In JavaScript, any function can be instantiated as an object.

[Ctrl A Select all Note:
If you need to introduce external Js, you need to refresh to execute
]
This code passes new User () to create a new object of the function. The new object created has a name attribute, and the constructor attribute points to the function that created it.
3. Public methods

Public methods are always accessible to users in the context of the object. To implement this method, you need to use the prototype attribute-prototype.
The prototype of an object is still an object. After adding properties to a prototype object, every object instantiated by the prototype can access these properties, that is, these properties are public.
[Ctrl A Select all Note:
If you need to introduce external Js, you need to refresh to execute ]

4, private Method


[Ctrl A Select all Note: If you need to introduce external Js, you need to refresh to execute
]

5, privileges Method It accesses private variables in a public way.


[Ctrl A Select all Note:
If you need to introduce external Js, you need to refresh to execute
]Essentially, the privileged method is Dynamically generated. Because they are added to the object at runtime, not generated when the code is first compiled.
This ability to dynamically generate code cannot be underestimated. It is very useful to be able to generate code based on the time variables you want. Look at the following example of dynamic generation method:

[Ctrl A Select all Note:
If you need to introduce external Js, you need to refresh to execute
]
6, static Methods
The essence of static methods is no different from ordinary functions. Static methods can ensure the cleanliness of the object's namespace.
[Ctrl A select all Note: If you need to introduce external Js, you need to refresh to execute ]
2. Summary
It is very important to understand the concepts and content described in this chapter. This is the starting point for fully mastering professional JavaScript.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template