[OpenLayers-Dev] destroy

Tim Schaub tschaub at opengeo.org
Thu Jan 8 18:56:31 EST 2009


We don't currently have a uniform way of determining if an OpenLayers 
object has been "destroyed".  I'm wondering what people think of adding 
something like this:

OpenLayers.Object.destroy = function(obj) {
     for(var prop in obj) {
         delete obj[prop];
     obj.valueOf = function() {
         return false;

Then we could use the following to decide if something has already been 

obj == false // true after OpenLayers.Object.destroy(obj)


We'd have a uniform way of determining if the destroy method had been 


This only works for the level of type coercion done by the equality 
operator.  The logical not operator still considers the object truthy 
(so !OpenLayers.Object.destroy(obj) === false).  So, we'd probably still 
end up doing things like this (to test undefined or destroyed):

if(obj && obj != false) {...}

Also, maybe we're better off checking explicitly for properties as we do 
currently (!obj.events etc.)

Any opinions?

Tim Schaub
OpenGeo - http://opengeo.org
Expert service straight from the developers.

More information about the Dev mailing list