Created
May 1, 2018 19:02
-
-
Save yuens1002/3ff91b82439554ca9f49a0b44cf4e47b to your computer and use it in GitHub Desktop.
Data Binding with Proxy Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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