<script>
class Person{};
let p = new Person();
// 增加
p.name = "zx";
p["name"] = "zc"
p.say = function(){
console.log("你好!!!!");
}
p["say"] = function(){
console.log("磨耗");
}
console.log(p);
// 删除
delete p.name;
delete p["name"]
delete p.say;
delete p["say"];
console.log(p);
// 修改
p.name = "lj";
p["name"] = "lx"
p.say = function(){
console.log("欢迎")
}
p["say"] = function(){
console.log("立法")
}
p.say();
console.log(p);
// 总结:无论是新增、删除、还是修改等,它们都有两种书写的方式:p.xxx = ? 或者 p["xxx"] = ?
</script>
javascript的对象的增删改查
最新推荐文章于 2024-08-22 14:32:34 发布