JS 基本类型赋值,引用类型赋值问题

var a = 1;
var b = a;
a = 3;
console.log("a = " + a);
console.log("b = " + b);

var objA = {
    "name": "abc",
    "age": 100
};
var objB = objA;
objA.age = 200;

console.log("objA.age = " + objA.age);
console.log("objB.age = " + objB.age);


----------------------------------------------------------------------------------------------------


function Person() {
    this.color = ["yellow", "white"];
}

function SubPerson() {

}

SubPerson.prototype = new Person();
var male = new SubPerson();
console.log("male.color = " + male.color);
male.color.push("black");

var female = new SubPerson();
console.log("female.color = " + female.color);

不多说,慢慢体会

猜你喜欢

转载自blog.csdn.net/liubangbo/article/details/84917434