/*** 人类* @author rubekid*/
function Person(options){//私有属性var _name; //姓名 var _age; //年龄/*** 构造函数*/var _construct = function(){_name = options.name||"";_age = options.age||0;console.log("construct");}();this.getName = function(){return _name;};this.setName = function(name){_name = name;};this.getAge = function(){return _age;};this.setAge = function(age){_age = age;};
}//测试代码
var p = new Person({name:"rubekid",age:1
});
console.log(p.getAge());
p.setAge(4);
console.log(p.getAge());
转载于:https://www.cnblogs.com/rubekid/p/3863235.html