“Vue Object.defineProperty”的版本间的差异
跳到导航
跳到搜索
Jihongchang(讨论 | 贡献) |
Jihongchang(讨论 | 贡献) |
||
第19行: | 第19行: | ||
value:18 | value:18 | ||
}) | }) | ||
+ | console.log(person); | ||
+ | </script> | ||
+ | </body> | ||
+ | </html> | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | === 通过 Object.defineProperty 添加的属性遍历不到 === | ||
+ | <syntaxhighlight lang="html"> | ||
+ | <!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); | console.log(person); | ||
</script> | </script> |
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>