new
parent
e2150600c2
commit
2501e0a53a
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,28 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>数据代理</title>
|
||||
</head>
|
||||
<body>
|
||||
<!-- 数据代理: 通过一个对象代理另一个对象中属性的操作(读/写) -->
|
||||
<script type="text/javascript" >
|
||||
let obj1 = {
|
||||
x:100
|
||||
}
|
||||
let obj2 = {
|
||||
y:200
|
||||
}
|
||||
|
||||
Object.defineProperty(obj2,'x',{ //往obj2身上添加一个x属性,其值为obj1的x属性值
|
||||
get(){
|
||||
return obj1.x
|
||||
},
|
||||
set(value){
|
||||
obj1.x = value
|
||||
}
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue