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!