The specific code is as follows:
The code copy is as follows:
//Define the function
function people(name,sex,age){
this.name = name;
this.sex = sex;
this.age = age;
}
//Share isStudent and sayName methods
people.prototype = {
isStudent:true,
sayName:function(){
alert(this.name);
}
}
var people1 = new people('Han Meimei','Female',16); //Instantiated object 1
var people2 = new people('Li Lei','Male',17); //Instantiated object 2
//Let two objects say their names through sharing
people1.sayName();
people2.sayName();
//Judge them all by sharing parameters
if(people1.isStudent == people2.isStudent)alert('They are all students');
This article also mentions some relevant knowledge of JavaScript objects, which should not be difficult to understand. If you really don't understand, you can take a little Baidu.