批改状态:合格
老师批语:下次附上截图,要不时间长了,你都不知是什么意思 了
let a = 1;let b = a;//更新a的值为2a = 2;//输出b = 1,更新a的值,并不会影响b的值b = 1;
let obj1 {id:1,name:'iphone',let obj2 = obj1;//更新obj1的属性obj1.name = 'vivo';//输出obj2;name也变成vivo,引用传递会同步更新obj2.name = 'vivo';}
let f1 = (x) => (x = 10);let m = 5;f1(m);console.log(m);//输出m=5 函数中对参数的更新,并不会影响到入参const f2 = x => (x.a = 10);let o = { a: 1, b: 2 };console.log(o);f2(o);console.log(o);//输出{a: 10,b: 2}// 看上去函数中对于o.a的更新生效,实际上仍是值传递
let [a, b, c] = [1, 2, 3];console.log(a, b, c);//输出 1,2,3let x = 1,y = 2;//x,y的值对换[x,y] = [y,x];
let { id, name } = { id: 10, name: "手机" };//可以写成let {name,id}
// 数组传参let sum = ([a, b]) => a + b;console.log(sum([10, 20]));// 对象传参let getUser = ({ name, email }) => [name, email];console.log(getUser({ email: "tp@php.cn", name: "天蓬老师" }));
function hello(name) {this.name = name;console.log(this.name);}let f = hello.bind(obj, "天蓬老师");//输出的是hello的函数声明console.log(f());
function getName(name) {this.name = name;console.log(name);}let f = getName.call(name, "jack");//apply需要是数组let f1 = getName.apply(name, ["Tom"]);
const product = {data: [{ name: "电脑", price: 5000, num: 5 },{ name: "手机", price: 4000, num: 10 },{ name: "相机", price: 8000, num: 3 },],//get用来获取参数get total() {return this.data.reduce((t, c) => (t += c.price * c.num), 0);},//set用来修改参数set setPrice(price) {this.data[1].price = price;},};console.log("总金额 :", product.total);product.setPrice = 9988;
let response = "Success";switch (response.toLowerCase()) {case "fail":console.log("请求失败");break;case "success":console.log("请求成功");break;default:console.log("未知错误");}
score = 80;console.log(score >= 60 ? "及格" : "补考");
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号