function User(name,age) { var year = (new Date()).getFullYear() - age; this.getYearBorn = function () {//创建一个特权方法,能够访问到year变量,同时自身属于公共可访问的 return year; } } var user = new User('angela', 1989); alert(user.getYearBorn() == 26);