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 8697539

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:33:04+00:00 2026-06-13T01:33:04+00:00

here is the fiddle: http://jsfiddle.net/Xh4GU/1 or the code: function Vector() { var v =

  • 0

here is the fiddle: http://jsfiddle.net/Xh4GU/1
or the code:

function Vector()
{
    var v = new Array(123, 456, 789);

    this.getV = function()
    {
        return v;
    }
}

function Formulas()
{
    this.add = function(x, axis, units)
    {
        x[axis] += units;
    }
}

var vector = new Vector();
var formulas = new Formulas();

var v = vector.getV();
var vAdded = formulas.add(v, 0, 77)

document.write(v);

spits out: 200,456,789

Why is the first index of v being changed?
Thanks

  • 0 0 Answers
  • 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-13T01:33:05+00:00Added an answer on June 13, 2026 at 1:33 am

    Because the array is passed to formulas.add by reference the argument being passed formulas.add is a reference to the private array v, any changes you make to its contents will remain visible in the future.

    The fact that v is private doesn’t protect its contents when you hand out references to v to external code. It does prevent external code from grabbing v for itself and swapping v with another array, but the array itself can be modified (its values changed).

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

Sidebar

Related Questions

Here's my fiddle : http://jsfiddle.net/JWww3/ I'm not sure to understand why this code is
I have a fiddle here http://jsfiddle.net/WULsZ/1/ I load jQuery first and the code is
In the fiddle here http://jsfiddle.net/mjmitche/KvwGw/21/ , when you submit the form, a new form
Here's my fiddle: http://jsfiddle.net/mikeritter/prsfM/28/ Here's my jQuery: $(document).ready(function(){ function howdy(n){ alert('Howdy '+n+'!'); } function
Here is a fiddle of my code: http://jsfiddle.net/ZWQpb/ Here is the HTML: <div class=blog-entry>
Here's my fiddle: http://jsfiddle.net/e6kCH/15/ It may sound stupid, but I can't find a way
Here is my Fiddle: http://jsfiddle.net/LLFpp/ I'm just starting to learn CSS and Divs (moving
Here is my fiddle: http://jsfiddle.net/jamesbrighton/wxWgG/4/ HTML: <div> <p class=click>Click 1</p> <p>This should be ignored</p>
Here's the fiddle: http://jsfiddle.net/scZtb/1/ Be warned, as the title suggests, this might crash your
I have a fiddle here - http://jsfiddle.net/hhimanshu/SDr3F/2/ The left pane is already available I

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.