charlie21
2021-05-05 16:55:39 +08:00
1
JAVASCRIPT
let arr1 = [1,2,3,4];
let arr2 = arr1;
arr2[0] = 99;
console.log(arr2); // [99,2,3,4]
console.log(arr1); // [99,2,3,4]
JAVASCRIPT
let arr1 = [1,2,3,4];
let arr2 = [...arr1];
arr2[0] = 99;
console.log(arr2); // [99,2,3,4]
console.log(arr1); // [1,2,3,4]
JAVASCRIPT
let d1 = { x: 1, y:2 };
let d2 = d1;
d2.x = 80;
console.log(d2); // { x: 80, y: 2 }
console.log(d1); // { x: 80, y: 2 }
JAVASCRIPT
let d1 = { x: 1, y:2 };
let d2 = {...d1};
d2.x = 80;
console.log(d2); // { x: 80, y: 2 }
console.log(d1); // { x: 1, y: 2 }
关键词 js spread operator
2
PHP
$arr1 = [1,2,3,4];
$arr2 = $arr1;
$arr2[0] = 99;
var_export($arr2); // [99,2,3,4]
var_export($arr1); // [1,2,3,4]
PHP
$arr1 = [1,2,3,4];
$arr2 = &$arr1;
$arr2[0] = 99;
var_export($arr2); // [99,2,3,4]
var_export($arr1); // [99,2,3,4]
3
C#
int[] arr1 = new int[]{1,2,3,4};
int[] arr2 = arr1;
arr2[0] = 99;
Console.WriteLine(String.Join(" ", arr2)); // 99 2 3 4
Console.WriteLine(String.Join(" ", arr1)); // 99 2 3 4
C#
using System.Collections.Generic;
List<int> list1 = new List<int>{1,2,3,4};
List<int> list2 = new List<int>(list1);
list2[0] = 99;
list2.ForEach(Console.WriteLine); // 99 2 3 4
list1.ForEach(Console.WriteLine); // 1 2 3 4
C#
using System.Collections.Generic;
List<int> list1 = new List<int>{1,2,3,4};
List<int> list2 = list1;
list2[0] = 99;
list2.ForEach(Console.WriteLine); // 99 2 3 4
list1.ForEach(Console.WriteLine); // 99 2 3 4