复制代码 代码如下:
//以构造函数方式添加私有属性和方法
function person(name, age, address) {
this.name = name;
this.age = age;
this.address = address;
}
//以原型方式添加公有属性、方法
person.prototype = {
constructor: person,
showname: function () {
alert(this.name + this.age + this.address);
}
}
//使用
var person = new person(zhangsan, 22, 中国北京!);
person.showname();