Javascript isset

Discussion in 'JavaScript' started by kuser, Dec 29, 2012.

  1. #1
    is this correct?
    
    if (editor) {  editor.destroy(); } 
    
    Code (markup):

     
    kuser, Dec 29, 2012 IP
  2. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #2
    Pretty much... though your 'destroy' method may not actually unset the variable itself. I'd suggest also setting editor=null; in there just to be sure. You could also call "delete editor;" -- either or, I prefer treating it as a pointer, YMMV.

    Sucks that javascript doesn't have proper destructors... but like most C syntax legacy languages objects just kinda seem shoe-horned in there any-old way.
     
    deathshadow, Dec 30, 2012 IP
  3. AlaskaWebDesign

    AlaskaWebDesign Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I also prefer editor = null; You know the object is "nothing" and you don't worry about whether the syntax is working against a variable or property.
     
    AlaskaWebDesign, Jan 8, 2013 IP