Hacker News new | ask | show | jobs
by pzmarzly 749 days 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

[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

1 comments

Yes, 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.