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

前端之家收集整理的这篇文章主要介绍了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,"
");

原文链接:https://www.f2er.com/js/418109.html

猜你在找的JavaScript相关文章