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

  • SEARCH
  • Home
  • 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 7046179
In Process

The Archive Base Latest Questions

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

First let me preface this question by saying that I’m fairly new to Javascript.

  • 0

First let me preface this question by saying that I’m fairly new to Javascript.

I also understand that Javascript objects are passed by reference and primitives are passed by value [source].

That said, here’s my question (simplified example): I’m pulling in JSON data that contains a lot of different information and I need to put each different type of information into a <ul> that’s in another <ul> like this:

<ul class="car-tree">
  <li>
    <label>Sports Cars</label>
    <ul class="sport-cars">
      <li>Porsche</li>
      <li>Mercedes</li>
      <li>BMW</li>
    </ul>
  </li>
  <li>
    <label>Super Cars</label>
    <ul class="super-cars">
      <li>Ferrari</li>
      <li>Lamborghini</li>
    </ul>
  </li>
  <li>
    <!-- and so on... -->
  </li>
</ul>

I’m grabbing a template for the list above that contains everything except the inner most <li> tags and I’m trying to populate it like this:

var CarView = function(){

  var buildCarTree = function(){

    // Gets the JSON data from somewhere
    var jsonData = grabJsonData();

    // Grab the template and convert it into a jQuery object
    var template = $(grabCarTreeTemplate());

    // Adds sport car data to sports cars list
    this.addCars(template.find('.sports-cars'), jsonData.sportsCars);

    // Adds super car data to sports cars list
    this.addCars(template.find('.super-cars'), jsonData.superCars);

    // Add the car tree to some container
    $('#container-trees').append(template);
  }

  var addCars = function(container, carData){

    for(id in carData){
      $('<li/>', {
        text : carData[id].text
      }).appendTo(container);
    }
  }
};

var view = new CarView();
view.buildCarTree();

When you do this you get the template without the data being added in, although, if you add in console.log statements through out addCars you can see the data being added to the container argument.

I’m confused because from what I understand from the source I provided above:

…if you change the parameter itself…that won’t affect the item
that was fed into the parameter. But if you change the INTERNALS of
the parameter, that will propagate back up…

and I would have figured that appendTo would be changing the internals of the jQuery object. What’s the deal?

  • 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-28T02:37:11+00:00Added an answer on May 28, 2026 at 2:37 am

    It looks like you’re trying to call private var functions as if they were methods of the obj. Change to this and try:

    var CarView = function(){
    
      this.buildCarTree = function(){
    
        // Gets the JSON data from somewhere
        var jsonData = grabJsonData();
    
        // Grab the template and convert it into a jQuery object
        var template = $(grabCarTreeTemplate());
    
        // Adds sport car data to sports cars list
        this.addCars(template.find('.sports-cars'), jsonData.sportsCars);
    
        // Adds super car data to sports cars list
        this.addCars(template.find('.super-cars'), jsonData.superCars);
    
        // Add the car tree to some container
        $('#container-trees').append(template);
      }
    
      this.addCars = function(container, carData){
    
        for(id in carData){
          $('<li/>', {
            text : carData[id].text
          }).appendTo(container);
        }
      }
    };
    
    var view = new CarView();
    view.buildCarTree();
    

    EDIT: See this jsFiddle for working code: http://jsfiddle.net/eHrH6/

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

Sidebar

Related Questions

Let me preface this question with first stating that I'm new to GUI interfaces:
First off, let me preface this question by saying that my professor is firmly
First off, let me preface this question by stating that I'm really a pretty
First let me say that I really feel directionless on this question. I am
First let me state that, despite being a fairly new practitioner of TDD, I'm
Let me preface by saying this is the first live cakephp project for me.
Preface Let me start off by saying that I'm a relatively new programmer and
Let me preface my question by saying that I am completely unqualified to be
(PHP/MySQL) Let me preface by saying that this works, and that I'm wondering if
First let me say that I did see this article: How to remove AspxAutoDetectCookieSupport

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.