There are two types of data types in javascript:

  • Primitive data type value primitive type, such as Undefined, Null, Number, Boolean, String.
    • When this is replaced, the original reference type is replaced
  • Values of a reference type, that is, Object type Object type, such as Object, Array, Function, Date, etc.
    • This is replaced, and only the current reference type is changed
var obj1 = { value:'Take time 1' }; 
var obj2 = { value:'Take time 2' }; 
var foo = changeStuff(obj1); 
function changeStuff(obj){ 
    obj.value = 'Take time 3';  // The value of obj1 has also been changed
    obj = obj2;              //obj1 is not replaced by obj2 but obj is replaced by obj2
    return obj.value;        
} 
Copy the code
console.log(foo); // 'take time 2'
console.log(obj1.value); //' take time 3'
Copy the code

The entire object is replaced

let zero = mesh.material[0]; Material [0]
mesh.material[0] = mesh.material[1]
mesh.material[1] = zero;
Copy the code