[OpenLayers-Dev] [OpenLayers 3] type instantiation performance

Eric Lemoine eric.lemoine at camptocamp.com
Sun Oct 17 16:03:35 EDT 2010


On Sun, Oct 17, 2010 at 1:46 PM, Pierre Giraud
<pierre.giraud at camptocamp.com> wrote:
> So there's three different things I take away from what you write :
>  1 - We could gain a lot with the performance if we use simple object
> literals in the case where we instanciate BaseType classes (Pixel, Bounds,
> LonLat) and we don't call any methods on those objects. This is exactly what
> Andreas said in response to this message,
>  2 - You propose to change the way we write classes. I thought this is
> something you were against to not so long ago. I may be wrong but this
> appears to me like a way to modernize OpenLayers. I think I already told you
> about that I'm in favor of such a change.
>  3 - We could gain a bit with the library weight at the same time.
>
> About classes (2), in the "Pro Javascript Design Patterns" I recently read,
> they propose to provide inheritance like the following (complete example
> attached to this message):
> function extend(subClass, superClass) {
>   var F = function() {};
>   F.prototype = superClass.prototype;
>   subClass.prototype = new F();
>   subClass.prototype.constructor = subClass;
>   subClass.superclass = superClass.prototype;
>   if(superClass.prototype.constructor == Object.prototype.constructor) {
>     superClass.prototype.constructor = superClass;
>   }
> }
> Note: the "superclass" attribute helps decoupling classes.

Thanks Pierre.

Your "extend" function is very similar to my "OpenLayers.inherit"
function. Mine allows passing objects to mix in the prototype of the
subclass, but I'd agree that this isn't mandatory. Also, I don't like
the "superclass" thing too much personally, because I'd prefer to not
introduce more magic.

Cheers,

-- 
Eric Lemoine

Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex

Tel : 00 33 4 79 44 44 96
Mail : eric.lemoine at camptocamp.com
http://www.camptocamp.com


More information about the Dev mailing list