Use JavaScript to define the specification of a class as follows:
Specify the class name and the constructor, and the class name (the constructor name) to capitalize the first letter:
Copy Code code as follows:
function YourClass () {
}
Use this. Member variable to define (pseudo) private members within its constructor, and the best convention (pseudo) Private members are made up of lowercase letters with "_". This type of member is that each object has its own copy, also called an object (instance) member.
Copy Code code as follows:
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 starts with an uppercase letter (or the best convention (pseudo) Private member is a lowercase letter with "_"). )。 This member variable is a single copy of each object, also called a class member.
Copy Code code as follows:
Yourclass.prototype.arg3= "Arg3 ..."//define direct access do not enter a positive member variable
Yourclass.prototype._arg4= "Arg4 ...";/need to use SETXXX () getxxx () accessor to do input verification
Use the class name. prototype. member function name =function (_arga,_argb,...) {} "way to member functions.
Copy Code code as follows:
Yourclass.prototype.yourfucname=function (_arga,_argb,...) {
Do somethings
}
Do not use the this. function name =function (_arga,....) in constructors {} "way to define a member function, which is a service template that needs to be shared, and does not require that each object have an identical template, which is too wasteful and of little significance.