js object-oriented programming
1. Object-oriented programming
1. Process-oriented and object-oriented
## 1) Process-oriented: Focus on the process steps of how to solve a problem. The characteristic of programming is that each step of the process is implemented by functions, without the concept of classes and objects. 2) Object-oriented: Focus on which object solves the problem. The characteristic of programming is that a class appears, the object is obtained from the class, and this object solves the specific problem. For the caller, process orientation requires the caller to implement various functions by himself. Object-oriented only requires the caller to understand the functions of specific methods in the object, but does not need to understand the implementation details of the method.2. The three major characteristics of object-oriented
The three major characteristics of object-oriented are inheritance, encapsulation, and polymorphism. JS can simulate inheritance and encapsulation, but it cannot simulate polymorphism. Therefore, JS is an object-based language, rather than an object-oriented language in the traditional sense.3. The relationship between classes and objects
## 1) Classes are abstract, objects are concrete (classes It is the abstraction of the object, and the object is the concretization of the class)
2) Class is an abstract concept. It can only be said that a class has attributes and methods, but it cannot be assigned specific attributes. For example, humans have names, but we cannot say what their names are.
Creation method of pt object1.var obj = {}//Simple object plainObject object literal/object direct quantity
2. Constructor (feature: camel case naming rule)
1) The system’s own constructor
var obj = new Object();//Equivalent to var object = {}
2) Custom function encapsulation
// Only by adding parameters to the function can the function be customized, and you can change the corresponding functions in the function at will Parameter data must be a new object when producing an object
function Car(color){ this.color=color; this.name = "BMW"; this.height = "1400"; this.lang = "4900"; this.weight = 1000; this.health = 100; this.run = function(){ this.health -- ; } }
var car = new Car("red");
3. 3 steps of the internal principle of the object constructor
1) Implicitly add an object at the top of the function body: var this = {}
2) Execute the content in the function body
3) Implicitly return the this object
##3. Packaging class
1. It is impossible for original values to have properties and methods (undefined, null, number, boolean, string)
2. Some original values can be called after passing through the packaging class. var num=123;//Not an object var num1=new Number(123);//It is an object3. The process of implicit packaging class is as followsvar num = 4; num.len = 3;//隐式发生转换,新建一个数字对象,然后添加属性并赋值,最后删除这个对象,所以在执行过程中没有报错 console.log(num.len);//再新建一个数字对象,添加属性,所以最后输出为undefined var str="abcd"; str.length=2; console.log(str.length); //输出为4,在输出时原始值str包装类之后输出的为new String('abcd').length,字符串自带length属性,所以输出长度为4
"JS Tutorial"
The above is the detailed content of js object-oriented programming. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Essential tools for stock analysis: Learn the steps to draw candle charts in PHP and JS. Specific code examples are required. With the rapid development of the Internet and technology, stock trading has become one of the important ways for many investors. Stock analysis is an important part of investor decision-making, and candle charts are widely used in technical analysis. Learning how to draw candle charts using PHP and JS will provide investors with more intuitive information to help them make better decisions. A candlestick chart is a technical chart that displays stock prices in the form of candlesticks. It shows the stock price

Face detection and recognition technology is already a relatively mature and widely used technology. Currently, the most widely used Internet application language is JS. Implementing face detection and recognition on the Web front-end has advantages and disadvantages compared to back-end face recognition. Advantages include reducing network interaction and real-time recognition, which greatly shortens user waiting time and improves user experience; disadvantages include: being limited by model size, the accuracy is also limited. How to use js to implement face detection on the web? In order to implement face recognition on the Web, you need to be familiar with related programming languages and technologies, such as JavaScript, HTML, CSS, WebRTC, etc. At the same time, you also need to master relevant computer vision and artificial intelligence technologies. It is worth noting that due to the design of the Web side

With the rapid development of Internet finance, stock investment has become the choice of more and more people. In stock trading, candle charts are a commonly used technical analysis method. It can show the changing trend of stock prices and help investors make more accurate decisions. This article will introduce the development skills of PHP and JS, lead readers to understand how to draw stock candle charts, and provide specific code examples. 1. Understanding Stock Candle Charts Before introducing how to draw stock candle charts, we first need to understand what a candle chart is. Candlestick charts were developed by the Japanese

Introduction In today's rapidly evolving digital world, it is crucial to build robust, flexible and maintainable WEB applications. The PHPmvc architecture provides an ideal solution to achieve this goal. MVC (Model-View-Controller) is a widely used design pattern that separates various aspects of an application into independent components. The foundation of MVC architecture The core principle of MVC architecture is separation of concerns: Model: encapsulates the data and business logic of the application. View: Responsible for presenting data and handling user interaction. Controller: Coordinates the interaction between models and views, manages user requests and business logic. PHPMVC Architecture The phpMVC architecture follows the traditional MVC pattern, but also introduces language-specific features. The following is PHPMVC

The relationship between js and vue: 1. JS as the cornerstone of Web development; 2. The rise of Vue.js as a front-end framework; 3. The complementary relationship between JS and Vue; 4. The practical application of JS and Vue.

SOLID principles are a set of guiding principles in object-oriented programming design patterns that aim to improve the quality and maintainability of software design. Proposed by Robert C. Martin, SOLID principles include: Single Responsibility Principle (SRP): A class should be responsible for only one task, and this task should be encapsulated in the class. This can improve the maintainability and reusability of the class. classUser{private$id;private$name;private$email;publicfunction__construct($id,$nam

In high-concurrency scenarios of object-oriented programming, functions are widely used in the Go language: Functions as methods: Functions can be attached to structures to implement object-oriented programming, conveniently operating structure data and providing specific functions. Functions as concurrent execution bodies: Functions can be used as goroutine execution bodies to implement concurrent task execution and improve program efficiency. Function as callback: Functions can be passed as parameters to other functions and be called when specific events or operations occur, providing a flexible callback mechanism.

Introduction to JS-Torch JS-Torch is a deep learning JavaScript library whose syntax is very similar to PyTorch. It contains a fully functional tensor object (can be used with tracked gradients), deep learning layers and functions, and an automatic differentiation engine. JS-Torch is suitable for deep learning research in JavaScript and provides many convenient tools and functions to accelerate deep learning development. Image PyTorch is an open source deep learning framework developed and maintained by Meta's research team. It provides a rich set of tools and libraries for building and training neural network models. PyTorch is designed to be simple, flexible and easy to use, and its dynamic computation graph features make
