Skip to content

Instantly share code, notes, and snippets.

@simonwoo
Last active April 23, 2018 08:51
Show Gist options
  • Save simonwoo/ce7ca40fcfc642f1b36540ef3bd219a0 to your computer and use it in GitHub Desktop.
Save simonwoo/ce7ca40fcfc642f1b36540ef3bd219a0 to your computer and use it in GitHub Desktop.
proxy - vue.js
// 代理模式,将子属性代理到自身上
export function proxy (target: Object, sourceKey: string, key: string) {
sharedPropertyDefinition.get = function proxyGetter () {
return this[sourceKey][key]
}
sharedPropertyDefinition.set = function proxySetter (val) {
this[sourceKey][key] = val
}
Object.defineProperty(target, key, sharedPropertyDefinition)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment