There are two ways of doing this:
Method One: Prototype class--new
function people (name) {
THIS.N = name; var n = name; why not?
}
People.prototype.say = function () {
Alert ("Peo-hello" +n);
}
1. Calling and passing parameters
var p = new People ("Iwen");
P.say ();
2. Create subclasses and let them inherit
function Student () {
}
Student.prototype = new People ();
var supersay = Student.prototype.say; //define and use first
Student.prototype.say = function () { //subclass Student has its own method, the parent class also has, how to call the parent class?
Supersay.call (this);
Alert ("Stu-hello");
}
var s = new Student ();
S.say ();
3. Encapsulation of classes and making external references
Format: (function () {...} ()); Method Call method
(function () {
function people (name) {
THIS.N = name; var n = name; why not?
}
People.prototype.say = function () {
Alert ("Peo-hello" +n);
}
Window. people = people; //Let externally callable
}());
Method Two:
JS function constructs: Calls to classes, objects, and functions