delete只能删除属性,不能删除变量和原型链上的属性
1,对象属性删除
var obj = {
name: 'mary'
}
delete obj.name;
console.log(obj.name); // undefined
2、删除数组中的元素,删除值,不能删除索引
var arr = [1, 2, 3];
console.log(arr[0], arr[1], arr[2]); // 1, 2, 3
delete arr[1];
console.log(arr[0], arr[1], arr[2]); // 1, undefined, 3
3、直接用delelte删除不了变量
var aa = 1;
delete aa;
console.log(1); //1
4、删除不了原型链中的变量
function person() {
this.name = 'mary';
}
person.prototype.age = 22;
var obj = new person();
delete obj.age;
console.log(obj.age); // 22