<!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>
// 'use strict'
// 启用严格模式后会报错
var emp={
ename:'lida',
age:28,
salary:2500,
phone:123456
}
Object.defineProperty(emp,'salary',{
writable:false, //不可修改
enumerable:false, //不可遍历
configurable:false, //不可重新配置
value:25,//不能遍历 不能修改 不能遍历
})
emp.salary=3500
console.log(emp);
Object.defineProperties(emp,{
phone:{writable:false}, //不能修改
age:{writable:false,enumerable:false} //不能修改且不能遍历
})
console.log('emp',emp);
</script>
</body>
</html>