Object-oriented programming of JavaScript

xiaoxiao2021-03-06  41

Foreword: This tutorial is made by Tim Scarfe, editing a directory structure by javascriptkit.com. JavaScipRT is a good choice to write object-oriented web applications. It supports OOP. Because it supports inheritance through prototype Well as well as through properties and methods. Many developers try to abandon JS, try to use C # or Java because JS is not what he thinks of the right object-oriented language. Many people have not recognized JavaScript support inheritance. When you write When the subject's code. It can give you a very powerful energy. You can also use it to write a reused, packageable code.

The object is so great? The success of object-oriented thought is because it looks on the relationship between things and things in realities. Things have attributes and methods. If we describe a table lamp. We will say its height and width, such as 12cm. Lights "This action is its method. When it is in the open state. It can be lighted or dark (that is, the value of the brightness becomes larger or smaller).

JavaScript gives the ability to create objects for web applications. Objects When needed, the corresponding event will be triggered, after the code is encapsulated, it can be instantiated many times.

Create an object with new object ()

There are several ways to create objects in JavaScript, and different methods are available in different occasions. The easiest is to use new operators, for example: