title: How to extend Function with ES6 classes?
body: <p>ES6 allows to extend special objects. So it's possible to inherit from the function. Such object can be called as a function, but how can I implement the logic for such call?</p>
  
  <pre><code>class Smth extends Function {
    constructor (x) {
      // What should be done here
      super();
    }
  }
  
  (new Smth(256))() // to get 256 at this call?
  </code></pre>
  
  <hr>
  
  <p>Any method of class gets reference to the class instance via <code>this</code>. But when it is called as a function, <code>this</code> refers to <code>window</code>. How can I get the reference to the class instance when it is called as a function?</p>
  
  <p>PS: <a href="//ru.stackoverflow.com/q/517424/178988">Same question in Russian.</a></p>