Web Analytics Made Easy -
StatCounter how to destroy an Object - CodingForum

Announcement

Collapse
No announcement yet.

how to destroy an Object

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to destroy an Object

    Hello simple question
    if i creating object something like
    var foo=new MyObject()
    if now i like to delete it from the document hierarchy
    is foo=null if be good ?
    or its gona leave me the foo object filled with null?
    tnx

  • #2
    http://sharkysoft.com/tutorials/jsa/content/021.html

    Comment


    • #3
      You can tell if the variable or constant you're trying to delete failed because:

      delete object

      returns true or false depending on the success of the operation.

      An excellent demonstration exhibited by different browsers:

      Netscape & Gecko: (delete document) == true
      IE6: delete document throws an error "Object does not support this action"
      I seem to remember older IE's returning false though, which is why I even bothered to showcase this example ...
      Opera 6: (delete document) == true

      I *believe* assigning the value undefined to the object also achieves the same thing, but using the delete keyword in my opinion is much clearer.
      jasonkarldavis.com

      Comment


      • #4
        Also, just would like to point out, most of the time you don't even need to worry about deleting your variables.

        Javascript (like Java) has its own "garbage collector" which automatically deletes objects when there are no more references to them.
        jasonkarldavis.com

        Comment


        • #5
          Whatever you do, don't click on that link....

          Comment

          Working...
          X