function User(name,age,sex){
this.name = name;
this.age = age;
this.sex = sex;
/*私有方法*/
function getSex(){
console.log(this.sex);
}
/*特权方法*/
this.getName = function(){
return this.name;
}
}
/*公有方法*/
User.prototype.getAge=function(){
return this.age;
};
// User.prototype = new Person({
// name : "lee"
// })
var user=new User("zhang",'18','male')
console.log(user.getName());
console.log(user.getAge());
console.log(user.getSex()); //访问不了
js面向对象的例子(私有/公有/特权方法)-2
最新推荐文章于 2018-03-29 17:19:24 发布