使用'var undefined'来测试undefined是否有任何问题(Is there anything wrong with using 'var undefined' to test for undefined)
这个测试对于undefined有什么问题吗?
var undefined; if(x == undefined){ //do something }或这个:
function undefined(x){ return typeof x == 'undefined'; } if(undefined(x)){ //do something }jsLint不会抛出存储的单词错误,但代码似乎仍然工作...
Is there anything wrong with this test for undefined?
var undefined; if(x == undefined){ //do something }or this:
function undefined(x){ return typeof x == 'undefined'; } if(undefined(x)){ //do something }jsLint doesn't throws a reserverd word error, but the code still seems to work...
最满意答案
不要重新定义undefined 。
其他程序员期望undefined总是undefined ,而不是函数的功能。
人们经常使用typeof运算符来确保在用于测试undefined变量时引用错误不会被抛出。
如果有人向你这样做,你可以使用...
undefined = void 0;...将其还原。
Don't redefine undefined.
Other programmers expect undefined to always be undefined, not a function for function's sake.
People often use typeof operator to ensure a reference error is not thrown when used to test for variables that are undefined.
If anyone ever does this to you, you can use...
undefined = void 0;... to revert it back.
更多推荐
发布评论