Vue Object.defineProperty
Jihongchang(讨论 | 贡献)2024年7月28日 (日) 09:54的版本
https://www.bilibili.com/video/BV1Zy4y1K7SH?p=11
ES6 往对象上添加属性
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>回顾Object.defineProperty方法</title>
</head>
<body>
<script type="text/javascript">
let person = {
name:'张三',
sex:'男'
}
Object.defineProperty(person, 'age', {
value:18
})
console.log(person);
</script>
</body>
</html>
通过 Object.defineProperty 添加的属性遍历不到
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>回顾Object.defineProperty方法</title>
</head>
<body>
<script type="text/javascript">
let person = {
name:'张三',
sex:'男',
// age:18
}
Object.defineProperty(person, 'age', {
value:18
})
console.log(Object.keys(person));
console.log(person);
</script>
</body>
</html>