You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.2 KiB
47 lines
1.2 KiB
2 years ago
|
<!DOCTYPE html>
|
||
|
<html lang="en">
|
||
|
<head>
|
||
|
<meta charset="UTF-8">
|
||
|
<title>回顾Object.defineProperty方法</title>
|
||
|
<script type="text/javascript" src="../vue.js"></script>
|
||
|
</head>
|
||
|
<body>
|
||
|
<div id="root">
|
||
|
|
||
|
</div>
|
||
|
<script type="text/javascript">
|
||
|
Vue.config.productionTip = false
|
||
|
let number = 18
|
||
|
let person = {
|
||
|
name: 'Roger',
|
||
|
sex: 'male',
|
||
|
// age: '18'
|
||
|
}
|
||
|
Object.defineProperty(person, 'age', {
|
||
|
// value: '18',
|
||
|
// enumerable: true, // 控制是否可迭代遍历
|
||
|
// writable: true, // 控制是否可以修改
|
||
|
// configurable: true //控制是否可以删除
|
||
|
|
||
|
// get: function () 用于当调用的时候再获取值,可以简写为 get() {}
|
||
|
get: function () {
|
||
|
console.log('获取age')
|
||
|
return number
|
||
|
},
|
||
|
// set function() 用于修改数据是调用 可以简写 set()
|
||
|
set(value) {
|
||
|
console.log('新的值为', value)
|
||
|
number = value
|
||
|
}
|
||
|
})
|
||
|
console.log(Object.keys(person))
|
||
|
console.log(Object.keys(person).length)
|
||
|
for (let key in person) {
|
||
|
console.log(key)
|
||
|
console.log('@', person[key])
|
||
|
}
|
||
|
|
||
|
console.log(person)
|
||
|
</script>
|
||
|
</body>
|
||
|
</html>
|