Javascript / OOJS 中的子类化
我有一个具有多个实例的“A”类。我有一个类“B”,每个类“A”的实例都有多个实例。类“B”不需要依赖于其父实例的特殊方法,但它确实需要能够触发专门影响其父实例的方法。我如何构建这种关系?
需要明确的是,我并不是在描述“动物 --> 人类”(一个子集)。我正在描述“人类 --> 工具”,其中父级具有某些事物的许多实例,并且这些实例应该有权访问仅影响其占有父级实例的方法。
I've got a class "A" that has multiple instances. I've got a class "B" that has multiple instances per instance of class "A". The class "B" doesn't need special methods depending on the instance of its parent, but it does need to be able to trigger methods that effect specifically its parent instance. How do I structure this relationship?
To be clear, I'm not describing "Animal --> Human" (a subset). I'm describing "Human --> Tools", whereby the parent has many instances of something, and those instances should have access to methods that affect only their possessive parent instance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当你实例化 B 时,总是传入你当前的 A。
如果我正确理解你的问题?
When you instantiate B, always pass in your current A.
If I understand your question correctly?