在下面的代碼中,a.b的值是什麼? (這既不是未定義的,或者爲null也不是空字符串)如何用[](數組表示法)求解該算法
var a = {} ;
a.b = [] ;
//////////////////////a.b["hello"]="hello"; //comment, uncomment for testing it
trace(a.b) // output is invisible, something like blank string
trace((a.b).length); // 0 , this could be used but the index is string ie. "hello"
trace(a.b == undefined) ; // false
trace(a.b == null) ; // false
僞代碼:
if (a.b is not having any type of content inside)
{
//How to get inside this part, when a.b is not having any value
// do this
}
else
{
//do this
}
比方說,我有一個來檢查,如果「你好」被初始化與否的條件。假設我沒有初始化它。那麼我怎樣才能進入第一個條件塊(見僞代碼) – 2012-08-09 11:23:05
嗯,我不明白你的意思寫*內容* :)如果proprty是* undefined *這意味着proprty被創建('var a :Object = {}; ab;')但是沒有任何指向這個屬性的指針。如果財產存在並且它不是*未定義的*那麼這個財產指向一些價值或對象。 – eleven 2012-08-09 11:37:33