Almost 20 years ago, when JavaScript was born, it was just a simple web scripting language. If you forget to fill in the username, it jumps out a warning.
Today, it becomes almost omnipotent, from the front end to the back end, with a variety of unthinkable uses. Programmers use it to accomplish increasingly large projects.
The complexity of JavaScript code also goes up in a straight line. A single Web page that contains 10000 of lines of JavaScript code has long been commonplace. 2010, an engineer revealed that Gmail's code length is 443000 lines!
To write and maintain such complex code, you must use a modular strategy. At present, the industry's mainstream approach is to adopt "object-oriented programming." Therefore, how to achieve object-oriented programming JavaScript, has become a hot topic.
The trouble is that the JAVASCIPT syntax does not support "class", resulting in traditional object-oriented programming methods that cannot be used directly. Programmers have done a lot of exploring how to simulate "classes" with JavaScript. This paper summarizes the three methods of JavaScript definition "Class", discusses the characteristics of each method, and emphatically introduces the best method in my eyes.
==============================================
Three ways for JavaScript to define classes (class)
Author: Ruan Yi Feng
In object-oriented programming, classes (Class) are templates of objects (object) that define properties and methods that are common to the same set of objects (also known as "instances").
The JavaScript language does not support "classes," but you can simulate "classes" in some alternative way.
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/script/