SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    ********* Ornithologist AtomicPenguin's Avatar
    Join Date
    May 2002
    Location
    Vancouver, BC
    Posts
    459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Referring to parent object

    Hey guys.

    I have an object, "A", which contains another object "B", as an attribute.

    How do I get a hold of Object "A" from within "B"? i.e. I need to refer to the object that B is stored inside from within B's code. Is there some superclass equivalent of 'this' that I don't know about? ('parent'?!)

    Any idea?

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could set it up manually
    Code:
    function aObject()
    {
    this.b = new bObject( this );
    }
    
    function bObject( p )
    {
    this.parent = p;
    }
    But I don't know of any host property that covers it. Don't thinks there is one. 'parent' certainly wouldn't be it -- that's reserved for the parent window reference [img]images/smilies/wink.gif[/img]

    superclass stuff is available, but that's only if you propertly setup a prototype-inheritance chain -- which is messy in javascript and rarely worth it
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  3. #3
    ********* Ornithologist AtomicPenguin's Avatar
    Join Date
    May 2002
    Location
    Vancouver, BC
    Posts
    459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ahh! Marvellous. That makes absolute sense - and it's an elegant solution, too.

    Thanks very much!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •