function xxx.prototype(x)
function x.foo()
....
end
end
-- usage
x = xxx.prototype({ })
x.foo()
This is wasteful, as it means we have a copy of every function for every instance. Instead we should prototype objects more like the following:
Xxx = { }
Xxx.__index = Xxx
function Xxx.create()
local x = { }
setmetatable(x, Xxx)
return x
end
function Xxx:foo()
...
end
-- usage:
x = Xxx.create()
x:foo()
Currently in lua we have methods like
This is wasteful, as it means we have a copy of every function for every instance. Instead we should prototype objects more like the following: