Node server program Object-Oriented Programming

Source: Internet
Author: User

When JavaScript acts as another role, we pay more and more attention to JavaScript object-oriented development. Because of the emergence of node, JavaScript can be used as a server side.Program. But how can we implement good Object-Oriented Programming? JavaScript has many inheritance methods. Here I will only introduce how to implement object-oriented programming.

Scenario: There is a base database class basemodel and a database inheritance class usermodel. Obviously, usermodel inherits basemodel.

 
Function basemodel (tablename) {This. _ TABLE = tablename; // This _ table is the public variable myprivate; // This is the private variable this. add = function () {console. log ("youcan Add add operation here! "); }; Check = function () {}; // This is a private method} function usermodel () {This. checkuserlogin () {console. log ("checkuser") ;};} usermodel. prototype = new basemodel ("t_user"); method of last use: var userobj = new usermodel (); userobj. add (); userobj. _ table;

For the inheritance class, we can only access public methods and public variables, which cannot be accessed for the private usermodel method, this Inheritance mechanism is the same as C ++ and others.

This is a bit rough, and it's an amazing evening!

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.