class Star { play() { console.log('playing'); } } class Proxy { constructor() { this.star = new Star() } talk(price) { if (price > 1000) { this.star.play() } else { console.log('not allowed'); } } }
let proxy = new Proxy() proxy.talk(1000) proxy.talk(10000)
let obj = {} let pro = new Proxy(obj, { get(tar, key) { return tar[key] }, set(tar, key, val) { if (key == 'data') { tar[key] = val news.innerHTML = val } else { console.log('not allowed'); } } })