domQ can be extended, adding custom methods to domQ collections or custom static methods to the domQ object.
If you're writing JavaScript the way to do it is exactly the same as what you'd do for extending jQuery
This is how you can add an hypothetical foo
method to domQ collections:
{% tabs %} {% tab title="Vanilla Javascript" %}
( function( window ) {
window.domQ.fn.foo = function() {
return this;
};
} )( window );
{% endtab %}
{% tab title="ES Module" %}
import domQ from "domQ";
domQ.fn.foo = function() {
return this;
};
{% endtab %} {% endtabs %}
domQ('*').foo();
This is how you can add an hypothetical calcNumbers
static method to the Cash object:
{% tabs %} {% tab title="Vanilla Javascript" %}
( function( window ) {
window.domQ.calcNumbers = function( number1, number2 ) {
return ( number1 + number2 );
};
} )( window );
{% endtab %}
{% tab title="ES Module" %}
import domQ from "domQ";
domQ.calcNumbers = function( number1, number2 ) {
return ( number1 + number2 );
};
{% endtab %} {% endtabs %}
domQ.calcNumbers(10 + 2); // returns as 12