How to define classes (class) in JavaScript

Source: Internet
Author: User

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/

Related Article

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.