1.删除全局/非全局定义的对象的属性
obj = {a:1,b:2,c:3}
delete obj.a
console.log(obj) //Object {b: 2, c: 3}
var obj1 = obj = {a:1,b:2,c:3}
delete obj1.a
console.log(obj1) //Object1 {b: 2, c: 3}
2.直接用delete删除不了全局变量/局部变量
name = 'lily';
delete name;
console.log(name); //lily
varname = 'lily';
deletename;
console.log(name); //lily
2.delete删除不了原型链中的变量
function fun(){
this.name = 'mm';
}
var obj = new fun();
fun.prototype.age = 18;
deleteobj.age;
console.log(obj.age) //18
总结:delete用来删除js对象的属性,不能删除任何变量(全局、局部、原型链中的变量)。