title: javascript plugin wont return the length of elements
body: <p>I found a tutorial about writing a custom JavaScript plugin but I cann't get it working as I want to.
  I'm trying to see if the elements are present(length) but this returns an undefined value. When I use vanilla JavaScript it returns a value.</p>
  
  <pre><code>var $ = (function () {
  
      'use strict';
  
      var Constructor = function (selector) {
          if (!selector) return;
          if (selector === 'document') {
              this.nodes = [document];
          } else if (selector === 'window') {
              this.nodes = [window];
          } else {
              this.nodes = document.querySelectorAll(selector);
          }
      };
  
      Constructor.prototype.ready = function(callback) {
          if(callback &amp;&amp; typeof callback === 'function') {
              document.addEventListener("DOMContentLoaded", function() {
                  if(document.readyState === "interactive" || document.readyState === "complete") {
                      return callback();
                  }
              });
          }
      };
  
      Constructor.prototype.each = function (callback) {
          if (!callback || typeof callback !== 'function') return;
          for (var i = 0; i &lt; this.nodes.length; i++) {
              callback(this.nodes[i], i);
          }
          return this;
      };
  
      Constructor.prototype.addClass = function (className) {
          this.each(function (item) {
              item.classList.add(className);
          });
          return this;
      };
  
      var init = function (selector) {
          return new Constructor(selector);
      };
  
      return init;
  
  })();
  
  $('body').length;//not working
  document.querySelectorAll('body').length;//working
  $('body').addClass('active');//working
  </code></pre>