Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1111953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:37:51+00:00 2026-05-17T02:37:51+00:00

I have an object inside another object: function TextInput() { this.east = ; this.west

  • 0

I have an object inside another object:

function TextInput() {
    this.east = "";
    this.west = "";
}

TextInput.prototype.eastConnect = function(object) {
    this.east = object;
    object.west = this;
}

textInput1 = new TextInput();
textInput2 = new TextInput();

textInput1.eastConnect(textInput2);

puts(textInput1.east.name) // this gives undefined.

In the last statement I want to print out the object’s reference name, in this case: textInput2.

How do I do that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T02:37:52+00:00Added an answer on May 17, 2026 at 2:37 am

    Objects exist independently of any variables that reference them. The new TextInput() object knows nothing about the textInput1 variable that holds a reference to it; it doesn’t know its own name. You have to tell it its name if you want it to know.

    Store the name explicitly. Pass the name to the constructor and store it off in the .name property so it’s accessible later:

    function TextInput(name) {                  // Added constructor parameter.
        this.name = name;                       // Save name for later use.
        this.east = null;
        this.west = null;
    }
    
    TextInput.prototype.eastConnect = function(that) {
        this.east = that;
        that.west = this;
    }
    
    textInput1 = new TextInput("textInput1");   // Pass names to constructor.
    textInput2 = new TextInput("textInput2");
    
    textInput1.eastConnect(textInput2);
    
    puts(textInput1.east.name);                 // Now name is available.
    

    (As a bonus I also made a few stylistic changes. It’s better to initialize east and west to null rather than an empty string "". null better represents the concept of “no connection yet”. And consider that as an alternate for object.)

    This raises the question of why you want to print the name in the first place, though. If your goal is to be able to do this in general with any variable (for debugging purposes, say), then you ought to get rid of that notion. If you’re just trying to test that the connection was made properly, consider something like this:

    alert(textInput1.east === textInput2 ? "it worked" : "uh oh");
    

    This tests that the connection was made and uses the ternary ? : operator to print one of two messages.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code snippet inside a function that checks if an object exists
I basically have an object, extended with a function through its prototype. Inside that
I have the code (inside one object) onclick: this._addX.bind(this) and then inside another object
I have this function inside another function: def _sum(k): return sum([(-1) ** v *
I have a list object List<Documents> , and inside that I have another list
Say i have a object in dynamic memory (new) and inside one of its
I have this inside my spring xml file: <object type=Test.Web.Utilities.TestClass, Test.Web singleton=false id=TestClass> <property
I have a $database object that I need to reference inside another class. Would
I have a vector of UnderlyingClass pointers stored in another object, and inside a
I have a function that takes another function as a parameter. Something like this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.