[OpenLayers-Dev] destroy
Eric Lemoine
eric.c2c at gmail.com
Fri Jan 9 01:49:14 EST 2009
Hi
I was also thinking about an OpenLayers.Object.isDestroyed function to
check whether an object was destroyed (with
OpenLayers.Object.destroy). But I understand that your goal with using
valueOf was to avoid introducing such a function and rely on the
language constructs instead.
Thanks,
Eric
2009/1/9, Tim Schaub <tschaub at opengeo.org>:
> Hey-
>
> 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
> destroyed:
>
> obj == false // true after OpenLayers.Object.destroy(obj)
>
> Benefits:
>
> We'd have a uniform way of determining if the destroy method had been
> called.
>
> Drawbacks:
>
> 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
>
> --
> Tim Schaub
> OpenGeo - http://opengeo.org
> Expert service straight from the developers.
> _______________________________________________
> Dev mailing list
> Dev at openlayers.org
> http://openlayers.org/mailman/listinfo/dev
>
More information about the Dev
mailing list