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 7809621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:29:52+00:00 2026-06-02T03:29:52+00:00

Explanation on these two images The code showUserProfile: (user_data)-> console.log Routers.AppRouter showUserProfile(), user_data window.user_profile

  • 0

Explanation on these two images
image 1
image 2

The code

showUserProfile: (user_data)->
    console.log "Routers.AppRouter showUserProfile()", user_data
    window.user_profile = user_data

    playlists_both_people = user_profile['playlists']

    my_profile['playlists'].forEach (pl)-> playlists_both_people.push(pl)

    @playlists = new Playlists.Collections.PlaylistsCollection( playlists_both_people )

    $("#app").html( new Playlists.Views.User.ShowView(user_data).render().el )
    @ok()
  • 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-06-02T03:29:53+00:00Added an answer on June 2, 2026 at 3:29 am

    Now that everyone has finished beating you up, I’ll be nice and show you what you’re doing wrong.

    You have a simple referencing problem. You start out with the user_data object being passed to your function. Then you make another reference to what user_data points at here:

    window.user_profile = user_data
    

    Now your data looks like this:

    window.user_profile ->-+
                           |
                           +->- {playlists: [ ], ...}
                           |
    user_data ----------->-+
    

    Then you make another reference to user_data.playlists here:

    playlists_both_people = user_profile['playlists']
    

    And now you have this on your hands:

    window.user_profile ->-+
                           |
                           +->- {playlists: [ ], ...}
                           |      ^
    user_data ----------->-+      |
                                  |
    playlists_both_people --->----+
    

    And then you push a bunch of things onto the playlists_both_people array and wonder why it changed user_data.playlists as well. The diagram tells you why: you never made a copy of anything, you’re just referencing the same piece of data through multiple variables.

    You’re using Backbone so you have Underscore, perhaps _.clone can help you:

    playlists_both_people = _(user_profile['playlists']).clone()
    

    That will give you a (shallow) copy of user_profile.playlists (which is the same as user_data.playlists at this point) in playlists_both_people and the next forEach won’t change anything in user_data.

    Note that you still might have a double reference problem with window.user_profile. You can’t use just one _.clone to fix this possible problem though, you’d have to clone each member separately since _.clone only does shallow copies. However, you probably have jQuery around and $.extend supports deep copying so that might be an option.

    I’d also recommend against putting things directly in window. You’d be better off setting up a namespace for your application, say window.app, and then use that namespace:

    window.app.user_profile = ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my mind these two bits of code should work the same: window.location =
These two code snippets produce files with different file-permissions. Example 1 creates the expected
I'm just looking for a simple, concise explanation of the difference between these two.
I've recently created these two (unrelated) methods to replace lots of boiler-plate code in
Could someone give me an explanation for these two switches? Are they mutually exclusive?
These two queries seem to return the same results. Is that coincidental or are
I'm wondering why these two following conditions in SQL return different results First Condition
I need a brief explanation on how the two commands isdigit() and isalpha() work.
I am very confused between these two consistency models. Please give some timeline examples
I have these two lists: '(and 1 (or a b)) '( (a 0)(b 1)

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.