adi rohan adi rohan - 3 months ago 5x
jQuery Question

Add methods to function

I want to add method to a function such that i can call them in a chain

What i want to do:

If you have used jQuery , then you must have seen the syntax like


returns element


returns css value of property of element

How can i do it by defining custom methods with same syntax without using jQuery ?


Here is a simple one:

function Get( element_id ) {
    this.node = document.querySelector(element_id);
    this.css = function(prop, val) {};

var get = function( element_id )
    return new Get( element_id );