title: Defined a function that can be called as an object
body: <p>I have a function.</p>
  
  <pre><code>function obj(id){
      if (this.__proto__.constructor !== i) {
          return new i(id);
      }
      this.element = (typeof id === 'string') ? document.getElementById(id) : id;
      this.remove = function(){
          this.element.parentNode.removeChild(this.element);
      }
      this.cookie = function (name,value,expire){
          var now = new Date();
          var time = now.getTime();
          time += expire*1000; //in second
          now.setTime(time);
          document.cookie = name + '=' + value + '; expires=' + now.toUTCString() + '; path=/';
      }
  }
  </code></pre>
  
  <p>I can easily call method <code>remove</code> like <code>obj("someid").remove();</code>, but method <code>cookie</code>. Function cookie does not depend on <code>id</code>. </p>
  
  <p>How could I define object <code>obj</code> in order to call its methods with both ways <code>obj(id).remove()</code> and <code>obj.cookie()</code>?</p>