这是小提琴: http: //jsfiddle.net/Xh4GU/1 或代码:
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);
吐出:200,456,789
为什么 v 的第一个索引被更改?谢谢