简体   繁体   中英

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?

Can I find out the moduleId by doing something like

parent.name

and get the moduleId that way?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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