1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| const data = { text: 'default' }; const input = document.getElementById('input'); const span = document.getElementById('span');
const handler = { set(target, key, value) { target[key] = value; input.value = value; span.innerHTML = value; return value; } }; const proxy = new Proxy(data, handler);
input.addEventListener('keyup', function(e) { proxy.text = e.target.value; });
|