Class: Divided into public and private
function Person( n){
var name=n; //Private attribute
function hello(){} //Private method one
var hello2() = function(){} //Private method two
this.Name = "Zhang San"; //Public member one
this.Hello = function(){ //Public method one
this.Name; //Private methods and properties can be called in the public method
name;
}
}
Person.prototype.Age=20; //Public member two
Person.prototype.SayHi = function(){} //Public method two
var p = new Person("abc");
p.ShowAge=function(){ //Public method three
this.Age;
}
p.Gender="M"; / /Public member three
Inherited:
function Person(args){ //Parent class
this.Name = "李思";
}
function Studnt(a,b,c){ //Subclass
Person.apply(this,arguments); //Skill method one
Person.call(this,a,b,c); //Skill method two
}
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn