SORU
26 AĞUSTOS 2008, Salı


Tanımsız bir nesne özelliği tespit

Eğer JavaScript bir nesne özelliği tanımlanmamış ise kontrol etmek en iyi yolu nedir?

CEVAP
6 Ocak 2009, Salı


Kullanımı:

if (typeof something === "undefined") {
    alert("something is undefined");
}

Eğer bir bazı özelliklere sahip değişken bir nesne ise bu gibi aynı şeyi kullanabilirsiniz:

if (typeof my_obj.someproperties === "undefined"){
    console.log('the property is not available...'); // print into console
}

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • EEVblog

    EEVblog

    4 NİSAN 2009
  • ItZWaffleS420

    ItZWaffleS42

    9 EYLÜL 2011
  • Numberphile

    Numberphile

    15 EYLÜL 2011