JS 基本型別賦值,引用型別賦值問題
阿新 • • 發佈:2019-01-01
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);
不多說,慢慢體會