Skip to content

Instantly share code, notes, and snippets.

@anish2690
Created May 23, 2020 19:31
Show Gist options
  • Save anish2690/521abbe9589ee1a8ad1cceeea5ff68c3 to your computer and use it in GitHub Desktop.
Save anish2690/521abbe9589ee1a8ad1cceeea5ff68c3 to your computer and use it in GitHub Desktop.
Assign some random thing to the instance method
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