<html>
<script>
var person = {
name:"dwqs",
age:20,
interesting:"coding",
blog: "www.sap.com"
};
//定义sex属性,writable是false,所以不能修改
Object.defineProperty(person,"sex",{
writable:false,
value:"male"
});
console.log(person.sex); //male
//在严格模式下出错,非严格模式赋值被忽略
person.sex = "Jerry";
console.log(person.sex);
var prop = Object.getOwnPropertyDescriptor(person,"sex");
debugger;
</script>
</html>
给JavaScript的单个对象定义属性和属性的元数据
猜你喜欢
转载自blog.csdn.net/i042416/article/details/104965171
今日推荐
周排行