admin管理员组文章数量:1326118
It seems in JavaScript you can’t delete
function arguments but you
can delete
global variables from a function.
Why this behavior?
var y = 1;
(function (x) { return delete y; })(1); // true
(function (x) { return delete x; })(1); // false
It seems in JavaScript you can’t delete
function arguments but you
can delete
global variables from a function.
Why this behavior?
var y = 1;
(function (x) { return delete y; })(1); // true
(function (x) { return delete x; })(1); // false
Share
Improve this question
edited Aug 10, 2011 at 10:18
Mathias Bynens
150k54 gold badges222 silver badges250 bronze badges
asked Aug 10, 2011 at 10:11
antonjsantonjs
14.3k15 gold badges70 silver badges91 bronze badges
1
-
1
Both return
false
in normal use (i.e. not within the Firebug or browser console, which useeval()
). See my answer. – Tim Down Commented Aug 10, 2011 at 13:14
2 Answers
Reset to default 6Actually, neither should return true
, and indeed they don't in Firefox or Chrome (untested in other browsers). I imagine you tested this with Firebug or another browser console, which changes things due to the console using eval()
. delete
only deletes properties of an object and cannot normally delete a variable declared using var
, whatever the scope.
Here's an excellent article by Kangax on the subject: http://perfectionkills./understanding-delete/
Edit: Both return false
in normal use (i.e. not within the Firebug or browser console, which use eval()
). See Tim Down’s answer (it should be the accepted one).
本文标签: Behavior of delete operator in javascriptStack Overflow
版权声明:本文标题:Behavior of delete operator in javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742192385a2430453.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论