Last active
April 23, 2018 08:51
-
-
Save simonwoo/ce7ca40fcfc642f1b36540ef3bd219a0 to your computer and use it in GitHub Desktop.
proxy - vue.js
This file contains hidden or 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
// 代理模式,将子属性代理到自身上 | |
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