1.構(gòu)造函數(shù)
function Person(name,age,job) {
this.name = name;
this.age = age;
this.job = job;
this.showName = function () {
alert(this.name);
};
this.showAge = function () {
alert(this.age);
};
this.showJob = function () {
alert(this.job);
};
}
var Bob = new Person('bob',18,'產(chǎn)品汪');
Bob.showName();
2.原型模式
function Person(name,age,job) {
this.name = name;
this.age = age;
this.job = job;
}
// prototype原型
Person.prototype.showName = function () {
alert(this.name);
};
Person.prototype.showAge = function () {
alert(this.age);
};
Person.prototype.showJob = function () {
alert(this.job);
};
var Lucy = new Person('Lucy',19,'測(cè)試鼠');
alert(Lucy.showName());
3.構(gòu)造函數(shù)
function Person(name,age,job) {
this.name = name;
this.age = age;
this.job = job;
this.showName = function () {
alert(this.name);
};
this.showAge = function () {
alert(this.age);
};
this.showJob = function () {
alert(this.job);
};
}
var Bob = new Person('bob',18,'產(chǎn)品汪');
Bob.showName();