<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
function fn(){
var name = 'xiaoming';
var age = 19;
return{
getAge:function(){
return age
},
setAge:function(val){
if(val < 0 || val > 130){
console.log("年龄不合法");
return null;
}
return age = val
}
}
}
var f = fn();
f.setAge(100)
console.log(f.getAge());
</script>
</body>
</html>