How do JS Libs execute things on variables in a chain or as a singe?

I cant find how to do this or know the terminology so excuse me if this may be a duplicate.

How do I take a variable and add something like this to it:


let x = document.createElement("p");

x.pickle(); 

//let's say ".pickle" turns the text green. I do not want to use a normal function to do this like `setAtrribute` I want to do it through my own custom thing like ".pickle"


How do I do this as JS libraries do? Even if my example needs to be changed to make it work.