js面向对象的例子(私有/公有/特权方法)-2

来源:互联网 发布:吉诺比利十大诡异数据 编辑:程序博客网 时间:2024/04/27 22:29
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()); //访问不了

0 0
原创粉丝点击