JavaScript Object-oriented programming has some discrepancies with other OO languages, so there are some normative issues to be aware of when using JavaScript's object-oriented features. Here's a quick look at how JavaScript defines a class, and how you need to standardize your code as you define the class. Dingzhou Technology Industry Bureau
The specification for defining classes using JavaScript is as follows:
Specifies the class name and constructor, the first letter of the class name (constructor name):
function YourClass () {}
Use the this. Member variable to define (pseudo) private members within its constructor, preferably a contract (pseudo) private member consisting of a lowercase letter beginning with "_". This member is a different copy of each object, also called an object (instance) member.
function YourClass (_arg1,_arg2,...) { this._arg1=arg1; THIS._ARG2=ARG2; //...}
Use the class name. prototype member variable to define a member variable outside its constructor, preferably by agreeing that such a member begins with an uppercase letter (or the best convention (pseudo) Private member consists of a lowercase letter beginning with "_"). )。 This member variable is a copy, also called a class member, that each object shares.
Yourclass.prototype.arg3= "Arg3 ...";//define Direct access do not enter validation member variable yourclass.prototype._arg4= "Arg4 ...";//need to use SETXXX () GetXXX () accessors do input validation
Use the class name. prototype. member function name =function (_arga,_argb,...) {} "way to member functions.
Yourclass.prototype.yourfucname=function (_arga,_argb,...) { //do somethings}
Do not use the "this" function within the constructor. =function (_arga,....) {} "means to define member functions, which are service templates, need to be shared, and do not need to have an identical template for each object, which is wasteful and does not make much sense.
JavaScript defines classes in a way that differs from other OO languages