title: Chaining function not work when inside another function
body: <p>I try to create chaining function using vanilla javascript, its work if just chaining, but if inside other function its stop working.</p>
  
  <pre><code>var doc = document,
  M$ = function(el) {
    var expr = /^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/;
    var m = expr.exec(el);
    if(m[1]) {
      return doc.getElementById(m[1]);
    } else if(m[2]) {
      return doc.getElementsByTagName(m[2]);
    } else if(m[3]) {
      return doc.getElementsByClassName(m[3]);
    }
  },
  $ = function (el) {
    this.el = M$(el);
  
    // event function
    this.event = function(type,fn) {
      this.el.addEventListener(type,fn,false);
      return this;
    }
  
    // forEach function
    this.forEach = function(fn,val) {
      for(var i = this.el.length - 1; i &gt;= 0; i--) {
        fn.call(val, i, this.el[i]);
      }
      return this;
    }
  
    if(this instanceof $) {
      return this.$;
    } else {
      return new $(el);
    }
  };
  
  //use
  $("button").forEach(function(index, el) 
   // when i use function event, its not work
    el.event("click", function() {
      alert("hello");
    });
    // if i'm using addEventListener its work, but i want use event function
  });
  </code></pre>
  
  <p>My question is, how to be event function working inside forEach function?
  Thanks for help!</p>