I’ve been working on my own personal JavaScript library for a while now, and it works fine. But I’ve been wondering about the jQuery return object.
Lets say you have a few divs in your DOM and you select them with $("div") jquery actually returns the selected nodes (as an object/array?) in the console log and you can mouse-over them to see where they are in the documents.
My object actually returns the entire object itself, so if you call kj("div") (Where kj is my object name) it shows up like this in the console log:
> kj
> elements: Array[10]
> length : 10
> more stuff
My question is, how can I make it return something like jQuery?
Thanks in advance.
I think what you are looking for is that in jQuery the Array of elements is the primary object, the methods and other information is connected to that array as properties.
because
typeof Array === 'object'you can arbitrarily attach methods and properties to an array.