Created
August 23, 2019 17:43
-
-
Save CreatiCoding/976182e598b10d8bbb4b368eb29e9545 to your computer and use it in GitHub Desktop.
javascript pure watch
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
| // standard watch | |
| const watch = (obj, key, defalut_value, callback) => { | |
| Object.defineProperty(obj, key, { | |
| get() { | |
| return this._value || defalut_value; | |
| }, | |
| set(value) { | |
| this._value = value; | |
| callback(this._current); | |
| }, | |
| }); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment