今天写接口测试demo,发现js值引用问题

js 普通变量为值传递
js 对象为为引用传递
var a = 123;
undefined
var b=a;
undefined
a
123
b
123
b =234
234
a
123
a = 456
456
b
234
var o = {name:'lxb',age:21}
undefined
h = o
Object { name: "lxb", age: 21 }
h.width = 20
20
o
Object { name: "lxb", age: 21, width: 20 }

解决方案

function Dog(name, breed, color, sex) {
   this.name = name;
   this.breed = breed;
   this.color = color;
   this.sex = sex;
}

theDog = new Dog("Gabby", "Lab", "chocolate", "girl");

https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object/toSource

相关文章:

  • 2021-08-17
  • 2022-02-16
  • 2021-07-20
  • 2021-06-23
  • 2022-12-23
  • 2019-09-02
  • 2021-05-27
猜你喜欢
  • 2022-12-23
  • 2021-12-17
  • 2021-12-10
  • 2021-12-09
  • 2022-12-23
  • 2021-06-21
相关资源
相似解决方案