且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

是“自我”吗?必要?

更新时间:2023-10-26 19:16:04

自我是必要的你希望一个对象发送消息,好吧, self 。通过getter / setter访问属性有时也是有益的,在这种情况下,您还需要使用 self ,如 self.propertyname self.propertyname = value 。 (这些不等于 propertyname propertyname = value

self is necessary if you wish for an object to send messages to, well, itself. It is also occasionally beneficial to access properties through getters/setters, in which case you'll also need to use self, as in self.propertyname or self.propertyname = value. (These are not equivalent to propertyname or propertyname = value.