Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuens1002/3ff91b82439554ca9f49a0b44cf4e47b to your computer and use it in GitHub Desktop.
Save yuens1002/3ff91b82439554ca9f49a0b44cf4e47b to your computer and use it in GitHub Desktop.
Data Binding with Proxy Example
const AppNode = {
elm: document.createElement('div'),
attri: {
class: null,
style: {}
},
handler: {
get(target, prop, receiver) {
if (prop in target) return target[prop]
else throw new ReferenceError(`'${prop}' doesn't exist`)
},
set(target, prop, value, receiver) {
Reflect.set(...Args)
}
},
init(attr, name) {
this.elm.setAttribute(attr, name)
document.body.append(this.elm)
}
}
AppNode.init(...['id', 'app'])
const App = new Proxy(AppNode, AppNode.handler)
App.elm.innerText = 'this is a test'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment