前端学习(1817):前端面试题之作用域和值类型传递的参数2

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
    //第2题  值类型和引用类型的传递
			function Person(name, age, salary) {
				this.name = name;
				this.age = age;
				this.salary = salary;
			}

			function f1(person) {
				//var person = p;
				person.name = "ls";
				person = new Person("aa", 18, 10);
			}

			var p = new Person("zs", 18, 1000);
			console.log(p.name);//zs
			f1(p);
			console.log(p.name);//ls
    </script>
</body>
</html>

运行结果

猜你喜欢

转载自blog.csdn.net/weixin_43392489/article/details/107498008