Chciałbym sprawdzić, jeśli rozszerzony obiekt jest nadal deklarowany.
Mój ogólny obiekt to:
var test = test || {};
To działa dobrze:
if (('test' in window)){ console.log("test is there!"); };
Ale jeśli się rozszerzeję ...
test.hello = "Is this in window?";
Poniższa sprawdza nie daje żadnego wyniku.
if (('test.hello' in window)){ console.log("test.hello shout be there!"); };
Jak mogę sprawdzić, czy test.Hello jest zadeklarowany, czy nie?
0
hamburger
17 sierpień 2014, 12:41
1 odpowiedź
var test = test || {};
test.hello = "Is this in window?";
if ((test.hello)){ console.log("test.hello shout be there!"); }else{
console.log("boo");
}
0
light94
17 sierpień 2014, 08:47