AS3 获取/设置与重新分配值

发布于 2024-09-15 16:08:55 字数 50 浏览 2 评论 0原文

当您可以重新分配值时,获取/设置值的目的是什么?仅仅是因为你可以获取/设置私有变量吗?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

长伴 2024-09-22 16:08:55

使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文