【发布时间】:2023-03-17 04:55:01
【问题描述】:
我不断看到在元表上定义 __index 的两种方法:
Account = {}
Account.__index = Account
function Account.create(balance)
local self = { balance = balance }
return setmetatable(self, Account)
end
或者:
Account = {}
function Account.create(balance)
local self = { balance = balance }
return setmetatable(self, { __index = Account })
end
我无法完全理解两者之间的行为差异。有人可以启发我吗?
【问题讨论】:
标签: inheritance lua prototype metatable