title: Using library(element).function() or library.function() constructions in Javascript lib
body: <p>We have Javascript library:
  <div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>(function (global, factory) {
    factory(global);
  }(window , function() {
    var MyLib = function(elem) {
      return new MyLib.foo.init(elem);
    }
    MyLib.foo = {
      init: function(elem) {
        elem = typeof elem == 'string' ? window.document.getElementById(elem) : elem;
        this[0] = elem;
        return this;
      },
    
      test1: function() { // (1)
        window.console.log('test1 ' + this[0].nodeName);
        this[0].innerHTML = this[0].nodeName;
      },
    };
  
    MyLib.foo.init.prototype = MyLib.foo;
    MyLib.test2 = function() { // (2)
      window.console.log('test2');
    }
  
    window.MyLib = window.ml = MyLib;
  }));
  
  function outerFunc(elem) {
    ml(elem).test1();
    ml.test2();
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Example&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
    &lt;script type="text/javascript" src="example.js"&gt;&lt;/script&gt;   
    &lt;div onclick="outerFunc(this)"&gt;button&lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>When should we create functions like (1) and when like (2)?<br>
  Of course, if it needs to get an element, we would <strong>always</strong> use <strong><em>(1)</em></strong>, like MyLib().myFunc(), am I right?<br>
  And for all situations, where an element is not affected, we should create <strong><em>(2)</em></strong> ,like MyLib.myFunc()?<br>
  May be we miss something with variables' protection?</p>