[js]面向对象2
delete删除属性
删除对象的属性
删除未用var定义的变量.
- delete返回布尔
- 删除不存在的属性,返回true
- 无法删除原形中的属性 如
delete obj.toString()
resu=delete obj.name;
# resu返回值是true
var num1=100;
console.log(num1);
console.log(window.num1);
# 100 100
num1=100;
console.log(num1);
console.log(window.num1);
# 100 100
var num1=100;
delete(num1);
console.log(window.num1);
# 100
num1=100; //未使用var,可被delete删除
delete(num1);
console.log(window.num1);
## undefined