//JS中其实没有堆和栈的概念
//堆 相当于 电脑硬盘 长期存储数据(一般存储复杂数据类型(对象)) 由程序员释放
//栈 相当于 电脑内存条 电脑自动释放
//基本类型在内存中的存储
var str1 = "hello";
var str2 = str1;
str1 = "bye";
console.log(str1);//bye
console.log(str2);//hello
//复杂类型在内存中的存储
function Person(name,age,intro){
this.name = name;
this.age = age;
this.intro = intro;
}
var p1 = new Person('张盛超',30,"like IT");
var p2 = p1;
p1.name = "大超";
console.log(p1.name);//大超
console.log(p2.name);//大超
p2.name = "张盛超";
console.log(p1.name);//张盛超
console.log(p1 === p2);//true
//基本类型作为函数的参数
var num1 = 10,num2 = 20;
Fn(num1,num2);
console.log(num1,num2);//10 20 不变
function Fn(n1,n2){
n1 *= 2;
n2 /= 2;
console.log('n1' + '=' +n1);
console.log('n2' + '=' +n2);
}
//复杂类型作为函数的参数
function Person(name,age,sex){
this.name = name;
this.age = age;
this.sex = sex;
}
function func(person){
person.name = "张盛超";
}
var p = new Person("盛超",18,'男');
console.log(p.name);//盛超
func(p);//传递指针 地址相同
console.log(p.name);//张盛超