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 Object name within same Object

    Okay, got a tough one for you guys.

    I have a user-defined object being used in a webpage, let's call it Bob. We instantiate bob, like this :

    Objname = new Bob();

    Now, of course, 'Objname' refers to the new Bob object. Here's my problem: when Bob is initially instantiated, it's created containing code that refers to itself. Specifically, it contains static text that refers to elements of itself. The problem is I need to get a hold of the actual text 'Objname' in order to do this.

    This is all very abstract, but I can't really divulge any details without hitting you with a huge amount of code. Still, I hope my problem is clear. And, I (really!) don't want to instantiate Bob like this:

    Objname = new Bob('Objname');

    since it's really ugly. Any suggestions...?

  2. #2
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why do you need the name of the variable?
    If you call a method of a Bob object, then you already know the name, don't you?
    And if you need a reference to the object in the constructor, then you can use this to refer to that instance of Bob

  3. #3
    SitePoint Zealot simplyunique's Avatar
    Join Date
    Jun 2003
    Location
    Montreal
    Posts
    166
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sounds right to me
    Fonkuscious say: Sink a foot in into my code and stub your toe


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
  •