单例代码
- 作者: 附近地段友
- 来源: 51数据库
- 2022-08-17
Singleton = {};
local _instance;
function Singleton.getInstance()
if not _instance then
_instance = Singleton;
end
--'any new methods would be added to the _instance object like this'
_instance.getType = function()
return 'singleton';
end
return _instance
end
function Singleton:new()
print('Singleton cannot be instantiated - use getInstance() instead');
end
推荐阅读
