js如何向函數(shù)傳遞object類型?
例1
var person = {
name : "leaf"
};
function obj(o){
o.name = "kafu";
return o;
}
var result = obj(person);
console.log(result.name);// kafu
console.log(person.name);// kafu
例2
var person = {
name : "leaf"
};
function obj(o){
o = {
name : "kafu"
};
return o;
}
var result = obj(person);
console.log(result.name);// kafu
console.log(person.name);// leaf