js 面对对象编程:if 中可以使用那些作为推断条件呢
在所有编程语言中 if 是最长用的推断之一,但在 js 中到底哪些东西可以在 if 中式作为推断表达式呢
例如如何几行,只是少了一个括号,真假就完全不同,到底表示什么含义呢 var obj={}; obj
Funtext=function(){}; if(obj
Funtext) { alert("true obj
Funtext;"); } else { alert("false obj
Funtext"); } obj
Funtext=function(){}; if(obj
Funtext()) { alert("true obj
Funtext();"); } else { alert("false obj
Funtext()"); }1 第一类已定义的变量但未赋值在 if 中认为是假例如: var t; if(t) { alert("true 已定义未赋值"); } else { alert("false 已定义未赋值"); }2 第二类已定义的变量,赋值为空字符串在 if 中认为是假,赋值为其他的字符串,也就是是字符串中有字符就认为是真例如: var t; t=""; if(t) { alert("true t='';"); } else { alert("false t=''"); }if 推断是假再例如: var t; t=" "; if(t) { alert("true t=' ';"); } else { alert("false t=' '"); } t="111"; if(t) { alert("true t='111';"); } else { alert("false t='111&