<!doctype html>
<html>
<head>
<title>标题</title>
<meta charset="utf-8">
<script>
"use strict";
var emp={
id:1001,
name:"eric",
salary:10000
}
//设置id属性为只读
Object.defineProperty(emp,"id",{
writable:false,
configurable:false//不可逆
});
var id_attrs=
Object.getOwnPropertyDescriptor(
emp,"id"
);
console.dir(id_attrs);
Object.defineProperty(emp,"id",{
writable:true
});//报错: 不允许重定义id属性
//emp.id=1002;//报错:不允许给只读属性赋值
console.log(emp.id);
</script>
</head>
<body>
</body>
</html>