Created
May 23, 2020 19:31
-
-
Save anish2690/521abbe9589ee1a8ad1cceeea5ff68c3 to your computer and use it in GitHub Desktop.
Assign some random thing to the instance method
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
import moment from 'moment'; | |
Object.defineProperty(Vue.prototype, '$moment', { value: moment }); | |
/*it gives us a distinct advantage: properties created with a descriptor are read-only by default. | |
Instead, our read-only instance method protects our library, and if you attempt to overwrite it you will get "TypeError: Cannot assign to read only property".*/ | |
/* | |
We would normally set an object property like this: | |
Vue.prototype.$moment = moment; */ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment