JavaScript对象操作与 this 关键字深度解析
1. 对象属性的增删改操作
在JavaScript中,对象是动态的,这意味着我们可以对对象的属性进行添加、修改和删除操作。以下是一个示例代码:
let hat = {
name: "Hat",
price: 100
};
let boots = {
name: "Boots",
price: "100"
}
let gloves = {
productName: "Gloves",
price: "40"
}
gloves.name = gloves.productName;
delete gloves.productName;
gloves.price = 20;
let sumPrices = (...numbers) => numbers.reduce((total, val) =>
total + (Number.isNaN(Number(val)) ? 0 : Number(val)));
let totalPrice = sumPrices(hat.price, boots.price, gloves.price);
console.log(`Total: ${totalPrice} ${typeof totalPrice}`);
上述代码的操作流程如下:
1. 创建了三个对象: hat 、 boots 和 gloves 。
超级会员免费看
订阅专栏 解锁全文
6

被折叠的 条评论
为什么被折叠?



