Proxy

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" oninput="inputText(this)">
<h1>哈哈哈哈哈哈哈哈哈哈</h1>
</body>
<script>
    var p = new Proxy({
        name: "掌声"
    }, {
        get: function (target, handler) {
            return target[handler];
        },
        set: function (target, hanlder, value) {
            target[hanlder] = value;
            update();
            return true;
        }
    });
    function update() {
        document.querySelector("h1").innerText = p.name;
    }

    function inputText(that){
        p.name = that.value;
    }
</script>
</html>

  

posted @ 2022-09-16 20:49  <好嗨哦!>  阅读(19)  评论(0编辑  收藏  举报