<!DOCTYPE html>
<html lang="zh">
<head>
<title>Document</title>
</head>
<body>
<script>
var obj = {msg:"hello"};
//监听的对象(Object),'属性'(spring)
Object.defineProperty(obj,'msg',{
//当数据被获取,执行以下代码
get:function(){
console.log("数据被获取");
},
//当数据被设置,执行以下代码
set:function(){
console.log("数据被设置")
}
});
console.log(obj.msg)
</script>
</body>
</html>
网友评论