Guest User

Untitled

a guest
Jan 17th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. //dom_utils Class, keep this in a utils file of some sort
  2.  
  3. class dom_utils {
  4. constructor(selector) {
  5. this.node = selector;
  6. }
  7.  
  8. exists() {
  9. return typeof this.node !== 'undefined';
  10. }
  11. }
  12.  
  13. export default dom_utils;
  14.  
  15. //implement anywhere (probably inside a constructor)
  16. import dom_utils from '@/helpers/utilities';
  17.  
  18. class some_class(){
  19. constructor(){
  20. this.node = document.querySelector('.some-element');
  21. this.node.utils = new dom_utils(this.node);
  22. }
  23.  
  24. //then call utils inside your methods
  25. some_method(){
  26. let exists = this.node.utils.exists();
  27. }
  28. }
Add Comment
Please, Sign In to add comment