Hacker News new | ask | show | jobs
by andai 622 days ago
I like JS's flexibility too, but I have to point out that your object-oriented JS code is compiled into C++ classes by the v8 optimizer! (Unless you change their structure, in which case it gives up (deoptimization).)
1 comments

Does it compile something like this into a c++ class?

makeThing(options, usethistoo) { let foo = options.foo; let thistoo = usethistoo;

  return {
    functions...
  }
}
I'm not sure if "C++ class" is the right term, but it will certainly compile into a class behind the scenes [1]

You can use d8 to check what the class structure ends up looking like [2]

---

[1]: https://v8.dev/docs/hidden-classes

[2]: https://v8.dev/docs/d8