View Full Version : 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
adios
06-26-2002, 11:40 PM
http://sharkysoft.com/tutorials/jsa/content/021.html
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 :D...
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.
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. :)
adios
06-27-2002, 12:56 AM
Whatever you do, don't click on that link....:rolleyes:
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.