微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

JavaScript面向对象,除了原始数据类型,都是地址引用

javascript 数据类型

原始类型:数字、字符串、布尔、null、undefined 传值

对象类型:对象、数组、函数 传址 引用

--------------------------------------------------------------------------
var oldobj = {
    name: "zxc",sex: "male",age: "24",address: "beijing"
};

var oneObj = oldobj;
var twoObj = oldobj;
twoObj.name="heping";
console.log(oneObj,"
");
console.log(twoObj,"
");

{"heping","male","24","beijing"}
{"heping","beijing"}


var oldobj = {
name: "zxc",address: "beijing"
};

var oneObj = oldobj;
var twoObj = {};
for(item in oldobj) {
twoObj[item] = oldobj[item];
}
twoObj.name="heping";
console.log(oneObj,"
");

{"zxc","beijing"}


angular代码

this.oldobj = {
name: "zhang.x.c",age: "25",address: "beijing"
};

this.oneObj = this.oldobj;
this.twoObj = {};
for(let item in this.oldobj) {
this.twoObj[item] = this.oldobj[item];
}
this.twoObj.name = "heping";
console.log(this.oneObj,"
");
console.log(this.twoObj,"
");

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐