Implement jquery like functions addClass, removeClass and delay in Javascript
Mutating built-in prototypes is not a good idea. It's not only inelegant, it can also lead to conflicts when other scripts on the page expect the prototypes to be unmutated. (It can even damage future attempts to integrate functionality officially, if enough sites use the bad code.)

Instead of using Element.prototype, create your own class, and put methods onto its prototype.

If you want to emulate jQuery, you should probably select all elements that match the selector, not just the first one. (Using a collection of elements will also avoid errors if the collection is empty - jQuery doesn't error when methods are called on an empty collection)

The active flag would be more informative if it was named more precisely, perhaps call it methodInProgress.

that = this is an antipattern in modern Javascript. If you need to use the calling context from the outer scope, use arrow functions instead. (You're already using ES2015 in multiple places)

callback is a single word, not two, so the proper way to camelCase it would be to keep it as-is. Calling the arguments callBack instead could result in bugs later when other readers/writers of the code expect it to be formatted conventionally.

Promises should be reserved for asynchronous actions. If you're going to run something that's completely synchronous, using a Promise adds unnecessary and confusing noise. Consider having your functions return Promises only if they're asynchronous, and while processing the queue, if a callback returns a Promise, wait for the Promise to resolve before moving onto the next callback. If the callback doesn't return a Promise, you can still await it without errors, and the next queue callback will run immediately.

Since you have multiple methods which add callback to the queue and return this, consider passing those methods through a helper function to make the code a bit more DRY.

Refactored:



const $ = selector =&gt; new PsuedoJquery(selector);
class PsuedoJquery {
  constructor(selector) {
    this.elements = [...document.querySelectorAll(selector)];
    this.queue = [];
  }
  async runNext() {
    await this.queue.shift()();
    if (this.queue.length) {
      await this.runNext();
    } else {
      this.methodInProgress = false;
    }
  }
  register(callback) {
    this.queue.push(callback);
    // If errors are a possibility, catch them here
    if (!this.methodInProgress) {
      this.methodInProgress = true;
      this.runNext();
    }
  }
  makeChainable(callback) {
    this.register(callback);
    return this;
  }
  addClass(className) {
    return this.makeChainable(() =&gt; {
      for (const elm of this.elements) {
        elm.classList.add(className);
      }
    });
  }
  removeClass(className) {
    return this.makeChainable(() =&gt; {
      for (const elm of this.elements) {
        elm.classList.remove(className);
      }
    });
  }
  delay(ms) {
    return this.makeChainable(() =&gt; new Promise((resolve) =&gt; {
      setTimeout(resolve, ms);
    }));
  }
}

$('#test')
  .removeClass("red").delay(500)
  .addClass("blue").delay(500).delay(500).removeClass("blue")
  .delay(500).addClass("red").delay(500).removeClass("red")
  .delay(500).addClass("blue").delay(500).removeClass("blue")
  .delay(500).addClass("red").delay(500).removeClass("red")
.blue {
  background-color: blue;
}

.red {
  background-color: red;
}
&lt;div id="test" style="width: 150px; height: 150px; margin:10px;" class="red"&gt;&lt;/div&gt;