[OpenLayers-Dev] 2.10 and 2.11-RC1 OpenLayers.Class behavior changes

Andreas Hocevar ahocevar at opengeo.org
Sun Jul 24 17:38:15 EDT 2011


Hi Didier,

not sure if you've seen my follow-up mail. You need to re-assign the protoype after the snippet I posted. So the whole snippet would be:

var X= OpenLayers.Class({
   initialize:function() { this._p= "A.initialize";
OpenLayers.Console.info(this._p); },
   pa:"PA",
   p_:null,
   ma:function() { OpenLayers.Console.info("A.ma="+this.pa); }
});
xProto = X.prototype;
xProto.initialize = function() { this.p_= "A.initialize-new";
OpenLayers.Console.info(this.p_); }
X = xProto.initialize;
X.proto = xProto;

Note the last line.

Andreas.

On Jul 24, 2011, at 23:34 , RICHARD Didier wrote:

> 
>> Hi Richard,
>> 
>> you are right of course, my bad. You would have to re-assign the prototype
>> of the old class, which gets lost when you re-assign X. Something like
>> 
>> var X= OpenLayers.Class({
>>   initialize:function() { this._p= "A.initialize";
>> OpenLayers.Console.info(this._p); },
>>   pa:"PA",
>>   p_:null,
>>   ma:function() { OpenLayers.Console.info("A.ma="+this.pa); }
>> });
>> xProto = X.prototype;
>> xProto.initialize = function() { this.p_= "A.initialize-new";
>> OpenLayers.Console.info(this.p_); }
>> X = xProto.initialize;
>> 
> 
> It does still not make the trick (same exception arisen in both 2.10 et 2.11)
> 
>> Andreas.
>> 
>> On Jul 24, 2011, at 23:05 , RICHARD Didier wrote:
>> 
>>> 
>>>> Hey Schuyler,
>>>> 
>>>> I'm not concerned about breaking backwards compatibility here. We never
>>>> encouraged people to override the initialize method by re-assigning it
>>>> on
>>>> the prototype, and we always advertised the initialize method as
>>>> constructor. With 2.11, finally, the initialize method is a real
>>>> constructor, i.e.
>>>> 
>>>> X.prototype.initialize === X.
>>>> 
>>>> So instead of
>>>> 
>>>> X.prototype.initialize = function() { ... }
>>>> 
>>>> which we never encouraged people to do anyway, people could now do
>>>> 
>>>> X = X.prototype.initialize = function() { ... }
>>>> 
>>> 
>>> Thanks for remining this, but what about the new paradigm. Doing :
>>> 
>>> X= OpenLayers.Class({
>>>   initialize:function() { this._p= "A.initialize";
>>> OpenLayers.Console.info(this._p); },
>>>   pa:"PA",
>>>   p_:null,
>>>   ma:function() { OpenLayers.Console.info("A.ma="+this.pa); }
>>> });
>>> X = X.prototype.initialize = function() { this.p_= "A.initialize-new";
>>> OpenLayers.Console.info(this.p_); }
>>> try {
>>>   var x1= new X();
>>>   OpenLayers.Console.assert((x1 instanceof X));
>>>   OpenLayers.Console.assert((x1.p_=="A.initialize-new"));
>>>   x1.ma();
>>> } catch(ex) {
>>>   OpenLayers.Console.warn(ex);
>>> }
>>> 
>>> gives :
>>> TypeError: x1.ma is not a function
>>> 
>>> It does not although work with 2.10 (same exception).
>>> Did I miss something ?
>>> 
>>> didier
>>> 
>>>> Andreas.
>>>> 
>>>> On Jul 24, 2011, at 22:07 , Schuyler Erle wrote:
>>>> 
>>>>> 
>>>>> On Jul 24, 2011, at 4:43 AM, RICHARD Didier wrote:
>>>>> 
>>>>>> With 2.10, overloading constructors was as simple as overwriting the
>>>>>> initialize prototype :
>>>>>> 
>>>>>> X.prototype.initialize= function () { ...}
>>>>>> 
>>>>>> In 2.11-RC1, it breaks as the new prototype is not the constructor !
>>>>>> ...
>>>>>> 
>>>>>> BTW, as this new OpenLayers.Class is a major change in OpenLayers,
>>>>>> don't
>>>>>> you thing it is more a 3.0 feature than a 2.x ?
>>>>> 
>>>>> I confess I'm a little concerned about this... Are we breaking
>>>>> backwards
>>>>> compatibility with such a change?
>>>>> 
>>>>> SDE_______________________________________________
>>>>> Dev mailing list
>>>>> Dev at lists.osgeo.org
>>>>> http://lists.osgeo.org/mailman/listinfo/openlayers-dev
>>>> 
>>>> 
>>>> 
>>>> --
>>>> Andreas Hocevar
>>>> OpenGeo - http://opengeo.org/
>>>> Expert service straight from the developers.
>>>> 
>>>> 
>>> 
>>> 
>>> --
>>> RICHARD Didier - Chef du pôle technique du Géoportail
>>> 2/4, avenue Pasteur - 94165 Saint Mandé Cedex
>>> Tél : +33 (0) 1 43 98 83 23
>>> _______________________________________________
>>> Dev mailing list
>>> Dev at lists.osgeo.org
>>> http://lists.osgeo.org/mailman/listinfo/openlayers-dev
>> 
>> --
>> Andreas Hocevar
>> OpenGeo - http://opengeo.org/
>> Expert service straight from the developers.
>> 
>> 
> 
> 
> -- 
> RICHARD Didier - Chef du pôle technique du Géoportail
> 2/4, avenue Pasteur - 94165 Saint Mandé Cedex
> Tél : +33 (0) 1 43 98 83 23
> _______________________________________________
> Dev mailing list
> Dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-dev

-- 
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.



More information about the Dev mailing list