3 ms·
Aren't Lua metatables and JS prototypes almost the same mechanism? I say almost, because I think metatables are more broad than JS prototypes - you can emulate
by pzmarzly 2y ago
Aren't Lua metatables and JS prototypes almost the same mechanism?
I say almost, because I think metatables are more broad than JS prototypes - you can emulate JS prototypes behavior using Lua metatables[0], but I don't think the reverse can be done (maybe with some Proxy[1] hackery?).
[0] https://www.lua.org/pil/13.4.1.html https://www.lua.org/pil/13.4.1.html
[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- int_19h 2y agoYes, you're right, `__index` does behave a lot like `__proto__`. I often forget that it is one of the few entries in the metatable that doesn't have to be a function.