JavaScript中delete操作符
深入理解JavaScript中delete操作符,特此记录下。
参考: http://xo-tobacoo.iteye.com/blog/346644 http://xiaolele.iteye.com/blog/682242 http://perfectionkills.com/understanding-delete/
深入理解JavaScript中delete操作符,特此记录下。
参考: http://xo-tobacoo.iteye.com/blog/346644 http://xiaolele.iteye.com/blog/682242 http://perfectionkills.com/understanding-delete/
评论功能维护中,当前仅展示历史评论。
是这样的,如果是全局变量,那么它是全局对象的一个属性(比如在浏览器中,全局的var x;就是在window上声明了一个属性x),任何对该对象的访问可以视为访问全局对象的属性。 故 ,在全局作用域:
等效于
所以全局的会被删除。 局部变量不是任何对象的属性,所以delete不会起作用(一定要严格点说的话with块内的属性也可以删除。。。。。。。。。。)
全局变量可以delete,局部变量不可以。 var x=1; delete x; alert(x) 这样显示undefined function test(){ var x=1; delete x; alert(x) } 这样执行test显示是1 function test(){ x=1; delete x; alert(x) } 这样执行test显示undefined
内容里有矛盾 var x = 1; delete x; 在我浏览器里试x是删除了, 可是在博客里说没有删除。
还是总结下,在发布出来吧
主要是记录下,慢慢体会。
呃 你这样会被投隐藏的