最近學了
JS的by refenerce用法
跟JAVA 的by value 去比較
我這邊的理解是一模一樣 為什麼名稱會不一樣呢?
這裡有點不太理解 希望有高人能指點一下
JS:
var c = { greeting: 'hi' };
var d;
d = c;
c.greeting = 'hello';
console.log(c);
console.log(d);
// by reference (even as parameters)
function changeGreeting(obj) {
obj.greeting = 'Hola'; // mutate
}
changeGreeting(d);
console.log(c);
console.log(d);
JAVA:
public static void main(String[] args) {
StringBuffer a = new StringBuffer("A");
StringBuffer b = new StringBuffer("B");
StringBuffer c = a;
operate(a,b);
System.out.println(a+","+b);//AB,B
System.out.println("c:" + c);
}
static void operate(StringBuffer x,StringBuffer y){
x.append(y);
y=x;
}
https://pjchender.blogspot.tw/2016/03/javascriptby-referenceby-value.html
這是那堂課的相關筆記 裡面提到JS是 by reference