4 ms·
I would be interesting to see exactly how much stuff is copied by the various implementations in such cases. There are obviously some stack or other data frame
by Roboprog 8y ago
I would be interesting to see exactly how much stuff is copied by the various implementations in such cases.
There are obviously some stack or other data frames that have to be captured somehow, but the code itself should in principle be something the VM makes a single copy of with references to in each object using it as a property. (Internally within a Function type reference, separate trackers for the instructions vs the bound data)
- BillinghamJ 8y agoNormally it could be effectively optimised away and just treated as an extra argument. But it's also required by the spec that `foo().method !== foo().method` when returning new functions from a closure in `foo`, so the function has to be wrapped and a new structure allocated each time to differentiate.
- Roboprog 8y agoThanks. I suspect the internals of “===“ in this case could look for the presence of a closure data pointer on a Function or some such hack. Anyway, I’d probably use an actual prototype on something (with “methods” and) hundreds of instances, but otherwise, I’m not too worried about just using closures and object literals.