AS3 获取/设置与重新分配值
当您可以重新分配值时,获取/设置值的目的是什么?仅仅是因为你可以获取/设置私有变量吗?
What's the purpose of getting/setting values when you can just reassign the value? Is it just because you can get/set private variables?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 getter 和 setter 与使用重新分配传递值的方法相同,只不过它是一种正式的执行方式。当你有 getter/setter 时,程序员会对它的工作方式抱有期望。通常它们没有重大副作用。
另请参阅此问题 - Why use getters and setters? - 了解为什么使用的原因getter 和 setter 根本没有。
Using getters and setters is the same as having a method that reassigns a passed value, except it is a formal way of doing it. When you have a getter/setter, the programmer will have expectations on how it will work. Usually they have no major side-effects.
Also refer to this question - Why use getters and setters? - for reasons why to use getters and setters at all.