interactiveRob
1/16/2019 - 7:14 PM

ES6 Dom Helpers/Utilities Boilerplate (to use instead of jQuery)

ES6 Dom Helpers/Utilities Boilerplate (to use instead of jQuery)

//dom_utils Class, keep this in a utils file of some sort

class dom_utils {
    constructor(selector) {
        this.node = selector;
    }

    exists() {
        return typeof this.node !== 'undefined';
    }
}

export default dom_utils;

//implement anywhere (probably inside a constructor)
import dom_utils from '@/helpers/utilities';

class some_class(){
    constructor(){
        this.node = document.querySelector('.some-element');
        this.node.utils = new dom_utils(this.node);
    }
    
    //then call utils inside your methods
    some_method(){
        let exists = this.node.utils.exists();
    }
}