简体   繁体   English

如何访问javascript对象的父对象

[英]how to access parent of javascript object

I have a slideshow class looking like this: 我有一个幻灯片放映课,看起来像这样:

//Our slideshow class
function Slideshow(moduleId) {

  this.moduleId = moduleId;

  this.activeSlide = null;

  this.slides = new Array();

  this.newRound();

}

and I instantiate it telling it what module it is on like this 我实例化它告诉它它在哪个模块上

self.modules[moduleId].slideshow = new Slideshow(moduleId);

Now as you can see, it is already "mounted" on a module named by the moduleId, so my question is: Is this object (the instance of Slideshow) aware of it's parent? 现在您可以看到,它已经“挂载”在由moduleId命名的模块上,所以我的问题是:这个对象(Slideshow的实例)是否知道它的父对象?

Can I find out the moduleId by doing something like 我可以通过做类似的事情找出moduleId

parent.name

and get the moduleId that way? 并以这种方式获取moduleId?

不可以。因为JavaScript通过引用传递对象,所以实际上同一Slideshow对象可以同时被多个“父”对象引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM