classList polyfill

by Artem

HTML

<div id="hello" class="hello"></div>

JavaScript

'use strict';

function ClassList(e) {
  this.e = e;
}

ClassList.prototype.contains = function(c) {
  return this.e.className.includes(c);
};

Reflect.defineProperty(HTMLElement.prototype, 'classList', {
  get: function() {
    return new ClassList(this);
  }
});

console.log(hello.classList.contains('hello'));