Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

An optimizing compiler could easily detect that a bunch of closures share an upvalue block in an enclosing "constructor" and then instead make that block explicit, and rewrite an entire constructor in a way that doesn't involve multiple closures at all (given that escape analysis and lang rules allow that). E.g.:

  // optimized
  function constructor(...) {
    let this = {...}
    function method(this, ...) {...}
    return function (name, ...) {
      switch (name) {
        case 'method': return method(this, ...)
          // or return a temp closure
          // like it does in tfa

  constructor()('method', 42)
And vice versa, on a computer that does closures in hardware better than objects for some unrealistic reason.

That's why both are just abstractions, whose semantics may better fit one or another implementation, but it really doesn't matter for maths.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: