//第一个实例
function employee(name,salary){
this.name = name;
this.salary = salary;
this.work = function(changename) {
this.name = changename;
}
}
var bill = new employee("bill", "100");
alert(bill.name + " " + bill.salary)
bill.work("代码");
alert(bill.name);
//第二个实例
function person(firstname, lastname, age, eyecolor) {
this.firstname = firstname;
this.lastname = lastname;
this.age = age;
this.eyecolor = eyecolor;
this.changeName = changeName;
function changeName(name) {
this.lastname = name;
}
}
myMother = new person("Sally", "Rally", 48, "green");
myMother.changeName("Doe");
document.write(myMother.lastname);
{
this.name = name;
this.age = age;
this.show = function(){
var res = "我是 " + this.name + " 年龄 " + this.age +".";
return res;
};
}
// 给person添加几个属性
Person.prototype.gender = "女";
Person.prototype.getSex = function() {
return this.gender;
};
//定义学生对象
function Student(num) {
this.num = num;
}
Student.prototype = new Person("alice", 23);
var s = new Student(123434);
console.log(s.show());
function employee(name,salary){
this.name = name;
this.salary = salary;
this.work = function(changename) {
this.name = changename;
}
}
var bill = new employee("bill", "100");
alert(bill.name + " " + bill.salary)
bill.work("代码");
alert(bill.name);
//第二个实例
function person(firstname, lastname, age, eyecolor) {
this.firstname = firstname;
this.lastname = lastname;
this.age = age;
this.eyecolor = eyecolor;
this.changeName = changeName;
function changeName(name) {
this.lastname = name;
}
}
myMother = new person("Sally", "Rally", 48, "green");
myMother.changeName("Doe");
document.write(myMother.lastname);
//第三个实例
//定义一个人
function Person(name, age){
this.name = name;
this.age = age;
this.show = function(){
var res = "我是 " + this.name + " 年龄 " + this.age +".";
return res;
};
}
// 给person添加几个属性
Person.prototype.gender = "女";
Person.prototype.getSex = function() {
return this.gender;
};
//定义学生对象
function Student(num) {
this.num = num;
}
Student.prototype = new Person("alice", 23);
var s = new Student(123434);
console.log(s.show());