Adding a function with the prototype to create a chain of functions

Asked

Viewed 12 times

1

I want to see how it works. I create a function like this:

function $( selector ){
    return document.querySelector( selector );
}

How do I create a function addClass() to use just like jQuery $("#foo").addClass("bar"), and in the future create a function chain like this: $("#foo").addClass("bar").setValue("value");

I make it clear that I don’t want to recreate jQuery, it’s just for learning.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.