当前位置: 首页 > news >正文

阿里云怎么创建网站广州工商注册查询网

阿里云怎么创建网站,广州工商注册查询网,wordpress 网页 登录,咨询公司取名字参考大全项目中有个公会对象#xff0c;数据大部分存在data中#xff0c;之前都是 u.data.point这样访问#xff0c;太麻烦了。 于是通过设置__index 使之可以直接访问属性#xff0c;u.point。 但是还是不能直接改属性#xff0c;u.point 4#xff0c;所以再设置了__newindex…项目中有个公会对象数据大部分存在data中之前都是 u.data.point这样访问太麻烦了。 于是通过设置__index 使之可以直接访问属性u.point。 但是还是不能直接改属性u.point 4所以再设置了__newindex。 在设置了setmetatable之后不能直接给u添加新属性因为设置了__newindex新的属性将直接加到u.data中的。 [c-sharp] view plaincopyprint? Union  {      data  nil,      dirty  nil,  }  --- 生成新的对象  function Union:new(o)      o  o or {}      setmetatable(o,self)      self.__index  self      return o  end  --- 初始化Union数据  function Union:init(data)      self:initTable()      self.data  data      local meta  {}      meta.__index  function (table, key)          if Union[key] ~ nil then              return Union[key]          else              return self.data[key]          end      end      meta.__newindex  function(table,key, value)          self.data[key]  value      end      setmetatable(self, meta)  end  function Union:initTable()      if self.data  nil then          self.data  {}      end      if self.dirty  nil then          self.dirty  {}      end  end  function Union:print()      print(self.point, self.data.point)  end  function pt()      print(data1.point, data2.point, u.point, u.data.point)  end  u  Union:new()  data1  {point  3}  data2  {point  103}  u:init(data1)  pt()  u.point  4  pt()  u.data  data2  pt()  u.point  104  pt()   Union { data nil, dirty nil, } --- 生成新的对象 function Union:new(o) o o or {} setmetatable(o,self) self.__index self return o end --- 初始化Union数据 function Union:init(data) self:initTable() self.data data local meta {} meta.__index function (table, key) if Union[key] ~ nil then return Union[key] else return self.data[key] end end meta.__newindex function(table,key, value) self.data[key] value end setmetatable(self, meta) end function Union:initTable() if self.data nil then self.data {} end if self.dirty nil then self.dirty {} end end function Union:print() print(self.point, self.data.point) end function pt() print(data1.point, data2.point, u.point, u.data.point) end u Union:new() data1 {point 3} data2 {point 103} u:init(data1) pt() u.point 4 pt() u.data data2 pt() u.point 104 pt() 通过修改__index和__newindex会获得不同的结果。 1.正确结果 [c-sharp] view plaincopyprint? function Union:init(data)      self:initTable()      self.data  data      local meta  {}      meta.__index  function (table, key)          if Union[key] ~ nil then              return Union[key]          else              return self.data[key]          end      end      meta.__newindex  function(table,key, value)          self.data[key]  value      end      setmetatable(self, meta)  end   function Union:init(data) self:initTable() self.data data local meta {} meta.__index function (table, key) if Union[key] ~ nil then return Union[key] else return self.data[key] end end meta.__newindex function(table,key, value) self.data[key] value end setmetatable(self, meta) end 3    103    3    3 4    103    4    4 4    103    103    103 4    104    104    104 2.错误的__newindex [c-sharp] view plaincopyprint? function Union:init(data)      self:initTable()      self.data  data      local meta  {}      meta.__index  function (table, key)          if Union[key] ~ nil then              return Union[key]          else              return self.data[key]          end      end      meta.__newindex  self.data      setmetatable(self, meta)  end   function Union:init(data) self:initTable() self.data data local meta {} meta.__index function (table, key) if Union[key] ~ nil then return Union[key] else return self.data[key] end end meta.__newindex self.data setmetatable(self, meta) end 3    103    3    3 4    103    4    4 4    103    103    103 104    103    103    103 3.错误的__index [c-sharp] view plaincopyprint? function Union:init(data)      self:initTable()      self.data  data      local meta  {}      meta.__index  function (table, key)          if Union[key] ~ nil then              return Union[key]          else              return data[key]          end      end      meta.__newindex  function(table,key, value)          self.data[key]  value      end      setmetatable(self, meta)  end   function Union:init(data) self:initTable() self.data data local meta {} meta.__index function (table, key) if Union[key] ~ nil then return Union[key] else return data[key] end end meta.__newindex function(table,key, value) self.data[key] value end setmetatable(self, meta) end 3    103    3    3 4    103    4    4 4    103    4    103 4    104    4    104 对象A在内部可以修改HP.外部对象只能访问对象A的HP,不能修改. 这东西其实可以用__index和__newindex来实现. __index指向对象A,这样就可以访问; __newindex重写,修改hp的话,就禁止.就可以完成他的需求. 下面给出简单的代码: function cannotModifyHp(object)     local proxy {}     local mt {         __index object,     __newindex function(t,k,v)         if k ~ hp then         object[k] v         end     end     }     setmetatable(proxy,mt)     return proxy end    object {hp 10,age 11} function object.sethp(self,newhp)     self.hp newhp end    o cannotModifyHp(object)    o.hp 100 print(o.hp)    o:sethp(111) print(o.hp)    object:sethp(100) print(o.hp) function cannotModifyHp(object) local proxy {} local mt { __index object, __newindex function(t,k,v) if k ~ hp then object[k] v end end } setmetatable(proxy,mt) return proxy end object {hp 10,age 11} function object.sethp(self,newhp) self.hp newhp end o cannotModifyHp(object) o.hp 100 print(o.hp) o:sethp(111) print(o.hp) object:sethp(100) print(o.hp)这里影响程序的不同结果是upvalue导致的。 由于一般程序中有可能动态改data。所以建议用function设置__index和__newindex尤其注意各个不同函数中self指向的是什么对象
http://www.yutouwan.com/news/325642/

相关文章:

  • my eclipse网站开发柳州网站建设工作室
  • 网站改版公司哪家好设计软件网站推荐
  • 网站制作模板代码html免费单位网站建设管理情况
  • wordpress博客模板安装失败成都最好的网站推广优化公司
  • 做游戏视频去哪个网站好wordpress调用搜索框
  • 建设网站的步郴州网站策划
  • 冒用公司名义做网站大麦网建设网站的功能定位
  • 郑州网站建设氵汉狮网络logo设计在线生成免费ai
  • 做网站软件_手机广州制作外贸网站公司
  • 网站开发(源代码)交互设计大学世界排名
  • 自己创建网站网站设计论文经济可行性分析
  • 域名解析平台网站建设新洲建设局网站
  • 网站开发完整视频平台类网站有哪些
  • 做电商设计有什么好的网站推荐谷歌商店安卓版下载
  • 广州市车管所网站建设网站开发容易吗
  • 成都微信微网站建设微信公众平台登录入口内村完小
  • 如何做好一个企业网站wordpress 获取头像地址
  • 网站设计大概在什么价位哪个网站做贷款推广
  • 重庆市建设工程信息网官网人员公示公告windows优化大师免费
  • 长沙企业模板建站ppt设计师兼职
  • dw网站建设的常用技术关键词推广效果
  • 长春网站建设公司排名做竞价网站 要注意什么
  • 甘肃建设监理协会网站外贸网站建设公司流程
  • 如何搭建一个完整的网站典型的四大综合门户网站
  • c语言开发网站教程网站建设如何找客户
  • 网站建设模板代码下载dedecms 调用 两个网站
  • 建设部网站核对编号公众号版影视网站开发
  • 银行门户网站建设ppt广告网站建设价格
  • 毕设做网站什么主题比较好经典软文案例200字
  • win7建设网站教程农村建设集团有限公司网站首页