What does .__index do?

What does .__index do?

local model = {}
model.__index = model

return model
1 Like

__index(table, index) : Fires when table[index] is indexed, if table[index] is nil. Can also be set to a table, in which case that table will be indexed.

Definition of index by merriam webster :

A list (as of bibliographical information or citations to a body of literature) arranged usually in alphabetical order of some specified datum (such as author, subject, or keyword)

Link to DevHub Metatables :

4 Likes